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

  1. Path: sparky!uunet!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: 26 Jan 1993 14:16:19 GMT
  6. Organization: Image Analysis Center, Univ. Hospitals of Cleveland
  7. Lines: 37
  8. Distribution: world
  9. Message-ID: <1k3h3jINNocv@usenet.INS.CWRU.Edu>
  10. References: <maurer.727751047@nova.Stanford.EDU> <1k1o90INNkdn@usenet.INS.CWRU.Edu>
  11. Reply-To: ellert@nu1.uh.cwru.edu
  12. NNTP-Posting-Host: max.uh.cwru.edu
  13.  
  14.  
  15. I wrote:
  16. >
  17. >In article <maurer.727751047@nova.Stanford.EDU>, Michael Maurer <maurer@nova.stanford.edu> writes:
  18. >>
  19. >>Hoping to start a trend, here is an unsolicited matlab m-file.
  20. >>MAT2STR is like NUM2STR, but operates on matrix input.
  21. >>Suggested improvements are welcome.
  22. >
  23. >Okay, here's an improvement, at least it should be since 1) it doesn't use
  24. >for loops in matlab, and 2) has far fewer function calls.  But I didn't
  25. >benchmark it.  Whenever I see those for loops I like to find ways to get
  26. >rid of them with matrix operations.
  27. >
  28. >function T=mat2str(X,nc)
  29. >%MAT2STR
  30. >%     T=mat2str(X) converts matrix X into string format T, using sprintf
  31. >%     to convert each element of X.
  32. >%     T=mat2str(X,nc) uses nc characters for each column, instead of
  33. >%     default 12.
  34. >
  35. >%     originally by Michael Maurer, 10 Jan 1992
  36. >%     modified by Ed Ellert, 25 Jan, 1993
  37. >
  38. >if nargin<2,
  39. >   nc=12;
  40. >end
  41. >
  42. >[mx,nx]=size(X);
  43. >T = reshape([setstr(X+'0'); ' '*ones((nc-1)*mx, nx)], mx, nx*nc);
  44.  
  45. Oops!  Walking to work this morning it occurred to me that this will only
  46. work for single digits.  It was fun though :^)
  47.  
  48. Ed Ellert
  49. ellert@nu1.uh.cwru.edu
  50.  
  51.