Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Help using "disp"
Date: Fri, 23 Jan 2009 10:32:01 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 17
Message-ID: <glc6b1$fr7$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>
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 1232706721 16231 172.30.248.38 (23 Jan 2009 10:32:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 23 Jan 2009 10:32:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1171274
Xref: news.mathworks.com comp.soft-sys.matlab:513366


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)