🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.soft-sys.matlab
Article #61

Re: SOURCE: mat2str.m - convert matrix to string format

#61
From: ellert
Date: Mon, 25 Jan 1993 22:06
31 lines
1559 bytes
In article <maurer.727751047@nova.Stanford.EDU>, Michael Maurer <maurer@nova.stanford.edu> writes:
>
>Hoping to start a trend, here is an unsolicited matlab m-file.
>MAT2STR is like NUM2STR, but operates on matrix input.
>Suggested improvements are welcome.

Okay, here's an improvement, at least it should be since 1) it doesn't use
for loops in matlab, and 2) has far fewer function calls.  But I didn't
benchmark it.  Whenever I see those for loops I like to find ways to get
rid of them with matrix operations.

function T=mat2str(X,nc)
%MAT2STR
%     T=mat2str(X) converts matrix X into string format T, using sprintf
%     to convert each element of X.
%     T=mat2str(X,nc) uses nc characters for each column, instead of
%     default 12.

%     originally by Michael Maurer, 10 Jan 1992
%     modified by Ed Ellert, 25 Jan, 1993

if nargin<2,
   nc=12;
end

[mx,nx]=size(X);
T = reshape([setstr(X+'0'); ' '*ones((nc-1)*mx, nx)], mx, nx*nc);

Ed Ellert
ellert@nu1.uh.cwru.edu
Technical Details
Message-ID: <1k1o90INNkdn@usenet.INS.CWRU.Edu>
Path: arc1-ca.pugleaf.net!sparky!uunet!gatech!udel!darwin.sura.net!spool.mu.edu!agate!usenet.ins.cwru.edu!v32.uh.cwru.edu!ellert
References: <maurer.727751047@nova.Stanford.EDU>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!gatech!udel!darwin.sura.net!spool.mu.edu!agate!usenet.ins.cwru.edu!v32.uh.cwru.edu!ellert
From: ellert@v32.uh.cwru.edu ()
Newsgroups: comp.soft-sys.matlab
Subject: Re: SOURCE: mat2str.m - convert matrix to string format
Date: 25 Jan 1993 22:06:23 GMT
Organization: Image Analysis Center, Univ. Hospitals of Cleveland
Lines: 31
Distribution: world
Message-ID: <1k1o90INNkdn@usenet.INS.CWRU.Edu>
References: <maurer.727751047@nova.Stanford.EDU>
Reply-To: ellert@nu1.uh.cwru.edu
NNTP-Posting-Host: max.uh.cwru.edu