Article View: comp.soft-sys.matlab
Article #68Re: DISP1: disp1.m - display text and numbers
From: rich
Date: Mon, 25 Jan 1993 23:42
Date: Mon, 25 Jan 1993 23:42
47 lines
2397 bytes
2397 bytes
In article <1993Jan25.142824.5268@news.columbia.edu> mnb2@cunixf.cc.columbia.edu (Mark Broadie) writes:
>Thanks for the comments about disp1.m. I realize you don't need
>an m-file for this, but it's easier. disp1.m takes up to 10
>arguments, with strings or numbers in any order. fprintf and
>sprintf are limited to 3 arguments.
ummm...no they aren't. For example:
>>fprintf('x = %3.1f, x2 = %3.1f, x3= %7.3f\n',x1,x2,x3);
x = 123.0, x2 = 321.0, x3= 3.000
>>
The ?printf functions have exactly the same format, strengths, and
weaknesses as the C ?printf commands, a feature that I'm sure implies
something deep about the way Matlab implemented this!
>
>In general, I find that display information 'nicely' is not easy
>with MATLAB. For example, does anyone have a *simple* way to
>display a small table with row and column headings. By simple,
>I mean not having to count spaces. For example, an m-file
>to display
>
> Col1 head Col2 heading Col3 head
>Row1 label 0.0 1.0 -3.4
>Row2 label here 0.0 1.0 -3.4
>Row3 label 0.0 1.0 -3.4
>
>
>>A=[0 1 -3.4;0 1 -3.4;0 1 -3.4];
>>fprintf('\t\tCol1 head\tCol2 head\tCol3 head\n');
>>fprintf('Row 1 label\t%6.1f\t\t%6.1f\t\t%6.1f\n',A(1,:));
>>fprintf('Row 2 label\t%6.1f\t\t%6.1f\t\t%6.1f\n',A(2,:));
...
will give you the correct look. Again, it's the same as C. By judicious
use of the tab (\t) and newline (\n) in some kind of print loop you can
easily write a .m file to output matrices of arbitrary size and labelling.
--
Rich Pawlowicz ----------------- INTERNET: rich@boreas.whoi.edu
Woods Hole Oceanographic Institution
"Home of the 99 cent squid burger (cheese extra)"
--------------------------------------------------------------
Technical Details
Message-ID:
<1993Jan25.234201.20734@netnews.whoi.edu>Path:
arc1-ca.pugleaf.net!sparky!uunet!cs.utexas.edu!asuvax!ncar!netnews.whoi.edu!newsReferences:
<1993Jan23.152729.26892@news.columbia.edu> <1993Jan25.103610.12912@afit.af.mil> <1993Jan25.142824.5268@news.columbia.edu>Show Full Headers
Complete Article Headers
Newsgroups: comp.soft-sys.matlab Path: arc1-ca.pugleaf.net!sparky!uunet!cs.utexas.edu!asuvax!ncar!netnews.whoi.edu!news From: rich@boreas.whoi.edu Subject: Re: DISP1: disp1.m - display text and numbers Message-ID: <1993Jan25.234201.20734@netnews.whoi.edu> Sender: news@netnews.whoi.edu Organization: Woods Hole Oceanographic Institution References: <1993Jan23.152729.26892@news.columbia.edu> <1993Jan25.103610.12912@afit.af.mil> <1993Jan25.142824.5268@news.columbia.edu> Date: Mon, 25 Jan 93 23:42:01 GMT Lines: 47