home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / softsys / matlab / 161 < prev    next >
Encoding:
Internet Message Format  |  1993-01-25  |  1.5 KB

  1. Path: sparky!uunet!gatech!udel!darwin.sura.net!spool.mu.edu!agate!usenet.ins.cwru.edu!v32.uh.cwru.edu!ellert
  2. From: ellert@v32.uh.cwru.edu ()
  3. Newsgroups: comp.soft-sys.matlab
  4. Subject: Re: SOURCE: mat2str.m - convert matrix to string format
  5. Date: 25 Jan 1993 22:06:23 GMT
  6. Organization: Image Analysis Center, Univ. Hospitals of Cleveland
  7. Lines: 31
  8. Distribution: world
  9. Message-ID: <1k1o90INNkdn@usenet.INS.CWRU.Edu>
  10. References: <maurer.727751047@nova.Stanford.EDU>
  11. Reply-To: ellert@nu1.uh.cwru.edu
  12. NNTP-Posting-Host: max.uh.cwru.edu
  13.  
  14.  
  15. In article <maurer.727751047@nova.Stanford.EDU>, Michael Maurer <maurer@nova.stanford.edu> writes:
  16. >
  17. >Hoping to start a trend, here is an unsolicited matlab m-file.
  18. >MAT2STR is like NUM2STR, but operates on matrix input.
  19. >Suggested improvements are welcome.
  20.  
  21. Okay, here's an improvement, at least it should be since 1) it doesn't use
  22. for loops in matlab, and 2) has far fewer function calls.  But I didn't
  23. benchmark it.  Whenever I see those for loops I like to find ways to get
  24. rid of them with matrix operations.
  25.  
  26. function T=mat2str(X,nc)
  27. %MAT2STR
  28. %     T=mat2str(X) converts matrix X into string format T, using sprintf
  29. %     to convert each element of X.
  30. %     T=mat2str(X,nc) uses nc characters for each column, instead of
  31. %     default 12.
  32.  
  33. %     originally by Michael Maurer, 10 Jan 1992
  34. %     modified by Ed Ellert, 25 Jan, 1993
  35.  
  36. if nargin<2,
  37.    nc=12;
  38. end
  39.  
  40. [mx,nx]=size(X);
  41. T = reshape([setstr(X+'0'); ' '*ones((nc-1)*mx, nx)], mx, nx*nc);
  42.  
  43. Ed Ellert
  44. ellert@nu1.uh.cwru.edu
  45.