Article View: comp.soft-sys.matlab
Article #74Re: SOURCE: mat2str.m - convert matrix to string format
From: ellert
Date: Tue, 26 Jan 1993 14:16
Date: Tue, 26 Jan 1993 14:16
36 lines
1731 bytes
1731 bytes
I wrote: > >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); Oops! Walking to work this morning it occurred to me that this will only work for single digits. It was fun though :^) Ed Ellert ellert@nu1.uh.cwru.edu
Technical Details
Message-ID:
<1k3h3jINNocv@usenet.INS.CWRU.Edu>Path:
arc1-ca.pugleaf.net!sparky!uunet!spool.mu.edu!agate!usenet.ins.cwru.edu!v32.uh.cwru.edu!ellertReferences:
<maurer.727751047@nova.Stanford.EDU> <1k1o90INNkdn@usenet.INS.CWRU.Edu>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!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: 26 Jan 1993 14:16:19 GMT Organization: Image Analysis Center, Univ. Hospitals of Cleveland Lines: 37 Distribution: world Message-ID: <1k3h3jINNocv@usenet.INS.CWRU.Edu> References: <maurer.727751047@nova.Stanford.EDU> <1k1o90INNkdn@usenet.INS.CWRU.Edu> Reply-To: ellert@nu1.uh.cwru.edu NNTP-Posting-Host: max.uh.cwru.edu