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

  1. Newsgroups: comp.soft-sys.matlab
  2. Path: sparky!uunet!cs.utexas.edu!asuvax!ncar!netnews.whoi.edu!news
  3. From: rich@boreas.whoi.edu
  4. Subject: Re: DISP1:  disp1.m - display text and numbers 
  5. Message-ID: <1993Jan25.234201.20734@netnews.whoi.edu>
  6. Sender: news@netnews.whoi.edu
  7. Organization: Woods Hole Oceanographic Institution
  8. References: <1993Jan23.152729.26892@news.columbia.edu> <1993Jan25.103610.12912@afit.af.mil> <1993Jan25.142824.5268@news.columbia.edu>
  9. Date: Mon, 25 Jan 93 23:42:01 GMT
  10. Lines: 47
  11.  
  12. In article <1993Jan25.142824.5268@news.columbia.edu> mnb2@cunixf.cc.columbia.edu (Mark Broadie) writes:
  13. >Thanks for the comments about disp1.m.  I realize you don't need
  14. >an m-file for this, but it's easier.  disp1.m takes up to 10 
  15. >arguments, with strings or numbers in any order.  fprintf and
  16. >sprintf are limited to 3 arguments.  
  17.  
  18. ummm...no they aren't. For example:
  19.  
  20.   >>fprintf('x = %3.1f, x2 = %3.1f, x3= %7.3f\n',x1,x2,x3);
  21.   x = 123.0, x2 = 321.0, x3=   3.000
  22.   >>
  23.  
  24. The ?printf functions have exactly the same format, strengths, and
  25. weaknesses as the C ?printf commands, a feature that I'm sure implies
  26. something deep about the way Matlab implemented this!
  27.  
  28.  
  29. >
  30. >In general, I find that display information 'nicely' is not easy
  31. >with MATLAB.  For example, does anyone have a *simple* way to
  32. >display a small table with row and column headings.  By simple,
  33. >I mean not having to count spaces.  For example, an m-file
  34. >to display
  35. >
  36. >                 Col1 head     Col2 heading      Col3 head
  37. >Row1 label           0.0            1.0             -3.4
  38. >Row2 label here      0.0            1.0             -3.4
  39. >Row3 label           0.0            1.0             -3.4
  40. >
  41.  
  42.   >>A=[0 1 -3.4;0 1 -3.4;0 1 -3.4];
  43.  
  44.   >>fprintf('\t\tCol1 head\tCol2 head\tCol3 head\n');
  45.   >>fprintf('Row 1 label\t%6.1f\t\t%6.1f\t\t%6.1f\n',A(1,:));
  46.   >>fprintf('Row 2 label\t%6.1f\t\t%6.1f\t\t%6.1f\n',A(2,:));
  47.      ...
  48.  
  49. will give you the correct look. Again, it's the same as C. By judicious
  50. use of the tab (\t) and newline (\n) in some kind of print loop you can
  51. easily write a .m file to output matrices of arbitrary size and labelling.
  52.  
  53. --
  54. Rich Pawlowicz ----------------- INTERNET: rich@boreas.whoi.edu
  55. Woods Hole Oceanographic Institution
  56. "Home of the 99 cent squid burger (cheese extra)"
  57. --------------------------------------------------------------
  58.