Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Help using "disp"
Date: Fri, 23 Jan 2009 13:49:02 +0000 (UTC)
Organization: Cambridge Univ
Lines: 31
Message-ID: <glchse$gk5$1@fred.mathworks.com>
References: <glc2bi$3ee$1@fred.mathworks.com> <glc2ms$pgd$1@fred.mathworks.com> <31d4740c-3b25-4ea9-a24a-f266923e2260@y1g2000pra.googlegroups.com> <glc6b1$fr7$1@fred.mathworks.com> <glc6ke$4gn$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1232718542 17029 172.30.248.38 (23 Jan 2009 13:49:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 23 Jan 2009 13:49:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 870214
Xref: news.mathworks.com comp.soft-sys.matlab:513400


fprintf is a pain. For generic formatting, use:

disp(['The answer is: ' num2str(ans)])

- Tom



"Daniel Eliasson" <danielel@kth.se> wrote in message <glc6ke$4gn$1@fred.mathworks.com>...
> "P" <pyjunk.nospam@shaw.ca> wrote in message <glc6b1$fr7$1@fred.mathworks.com>...
> > Hi again,
> > 
> > fprintf is very powerful but it does sometime to get use to syntax.
> > 
> > The magic format string '%3.1f' means 3 things
> > 
> > 1. 3 is Field Width, 'A digit string specifying the minimum number of digits to be printed'
> > 2. 1 is Precision, 'A digit string including a period (.) specifying the number of digits to be printed to the right of the decimal point'
> > 3. f implies fixed-point notation.
> > 
> > So yes you need to change the 1 to get to the other decimal. The %x.y formatting allows you to line up strings very nicely.
> > 
> > a=101
> > b=0.00001
> > fprintf('THIS IS %10.5f\n',a)
> > fprintf('THIS IS %10.5f\n',b)
> 
> 
> Thank you very much!
>