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

  1. Newsgroups: comp.soft-sys.matlab
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!howland.reston.ans.net!sol.ctr.columbia.edu!news.columbia.edu!cunixf.cc.columbia.edu!mnb2
  3. From: mnb2@cunixf.cc.columbia.edu (Mark Nathan Broadie)
  4. Subject: DISP1:  disp1.m - display text and numbers 
  5. Message-ID: <1993Jan23.152729.26892@news.columbia.edu>
  6. Sender: usenet@news.columbia.edu (The Network News)
  7. Nntp-Posting-Host: cunixf.cc.columbia.edu
  8. Reply-To: mnb2@cunixf.cc.columbia.edu (Mark Broadie)
  9. Organization: Columbia University
  10. Date: Sat, 23 Jan 1993 15:27:29 GMT
  11. Lines: 43
  12.  
  13. Trying to continue the trend, here is an m-file for display
  14. text and numbers to the screen on a single line.  I had m-files
  15. filled with statements like
  16.    disp('x measures blah blah, its value is');  disp(x);
  17. which (a) uses 2 display statements and (b) does not appear
  18. on a single line on the screen.  The m-file disp1.m allows the
  19. statement
  20.    disp1('x measures blah blah, its value is ', x);
  21.  
  22. Keep these submissions coming!
  23.  
  24. -mark broadie
  25.  
  26.  
  27. ------ cut here -------
  28.  
  29. function disp1(s1, s2, s3, s4, s5, s6, s7, s8, s9, s10);
  30. % DISP1
  31. % displays up to ten arguments on the screen
  32. % e.g., x = 2.3;
  33. %       disp1('x = ', x, ', 2*x = ', 2*x);
  34. % will print 'x = 2.3, 2*x = 4.6' on the screen
  35.  
  36. % Mark Broadie  1-20-93
  37. % Copyright (c) 1993.
  38.  
  39. s = [];
  40. for i = 1 : nargin;
  41.     x = eval(['s',int2str(i)]);
  42.  
  43.     % num2str.m code follows with '%.6g' replacing '%.4g'
  44.     if isstr(x)
  45.             t = x;
  46.     else
  47.             t = sprintf('%.6g',x);
  48.     end
  49.  
  50.     s = [s t];
  51.     end;
  52.  
  53. disp(s);
  54.  
  55. % end of disp1.m
  56.