home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / softsys / matlab / 118 < prev    next >
Encoding:
Text File  |  1993-01-23  |  1.9 KB  |  63 lines

  1. Newsgroups: comp.soft-sys.matlab
  2. Path: sparky!uunet!stanford.edu!nntp.Stanford.EDU!forsythe.stanford.edu!nova!maurer
  3. From: Michael Maurer <maurer@nova.stanford.edu>
  4. Subject: SOURCE: mat2str.m - convert matrix to string format
  5. Message-ID: <maurer.727751047@nova.Stanford.EDU>
  6. Sender: news@leland.Stanford.EDU (Mr News)
  7. Organization: STAR Lab, Stanford University, California USA
  8. Date: 23 Jan 93 01:04:07 GMT
  9. Lines: 52
  10.  
  11. Hoping to start a trend, here is an unsolicited matlab m-file.
  12. MAT2STR is like NUM2STR, but operates on matrix input.
  13. Suggested improvements are welcome.
  14.  
  15. #! /bin/sh
  16. # This is a shell archive, meaning:
  17. # 1. Remove everything above the #! /bin/sh line.
  18. # 2. Save the resulting text in a file.
  19. # 3. Execute the file with /bin/sh (not csh) to create the files:
  20. #    mat2str.m
  21. # This archive created: Fri Jan 22 16:55:43 1993
  22. export PATH; PATH=/bin:$PATH
  23. echo shar: extracting "'mat2str.m'" '(468 characters)'
  24. if test -f 'mat2str.m'
  25. then
  26.     echo shar: will not over-write existing file "'mat2str.m'"
  27. else
  28. sed 's/^XX//' << \SHAR_EOF > 'mat2str.m'
  29. XXfunction T=mat2str(X,nc,nd)
  30. XX
  31. XX%MAT2STR
  32. XX%    T=mat2str(X) converts matrix X into string format T, using sprintf
  33. XX%    to convert each element of X.
  34. XX%    T=mat2str(X,nc) uses nc characters for each column, instead of
  35. XX%    default 12.
  36. XX
  37. XX%    Michael Maurer, 10 Jan 1992
  38. XX%    Copyright (c) 1993 by Michael Maurer
  39. XX
  40. XXif nargin<2,
  41. XX   nc=12;
  42. XXend
  43. XX
  44. XX[mx,nx]=size(X);
  45. XXT=ones(mx,nc*nx)*abs(' ');
  46. XXfor i=1:mx,
  47. XX   for j=1:nx,
  48. XX      t=sprintf('%.4g',X(i,j));
  49. XX      T(i,nc*(j-1)+(1:length(t)))=t;
  50. XX   end
  51. XXend
  52. SHAR_EOF
  53. if test 468 -ne "`wc -c < 'mat2str.m'`"
  54. then
  55.     echo shar: error transmitting "'mat2str.m'" '(should have been 468 characters)'
  56. fi
  57. fi # end of overwriting check
  58. #    End of shell archive
  59. exit 0
  60. --
  61. ______________________________________________________________________
  62. Michael Maurer          maurer@nova.stanford.edu        (415) 723-1024
  63.