tags:

views:

346

answers:

4

I know about MATLAB's format long, format short, eng ... and so on. But short and long will always display a predefined number of decimals, with an exponent, and for example, format bank will display always 2 decimals.

Is there an option to put your explicit format, in a "fortran way", like f8.3 --> 1234.678 ?

I'm looking for a way to display numbers with 4 decimal points, and the rest ahead of the decimal point, with no exponent.

+3  A: 

According to the documentation it does allow you to format the number.

Also, the formatting is well documented as well.

monksy
It now occured, and I forgot to mention ... I wish to change it's format in matlab, not while printing to a file or ... I want to change the format matlab uses for displaying numbers while, for example, working in its interactive prompt.
ldigas
I'm not sure you can change that, that would probably be under the options if it is available. You can print the formatted number out manually.
monksy
+3  A: 

I don't know of a way to specify a global format of the type you want. sprintf('%15.4f', x) or num2str(x, '%15.4f') do what you're looking for, if you don't mind calling them explicitly each time.

mtrw
I see ... oh, well. I'll leave the question a little longer ... maybe someone will come up with some other idea ...
ldigas
+1 for the effort (to both), nevertheless ...
ldigas
+1. I came here to say this. I would point out that fprintf can be used to print to the console in addition to formatting. You could make a function print( dbl ) that does fprintf(1,"%5.3f\n",dbl) and use printf instead of disp.
KitsuneYMG
A: 

I just use sprintf and num2str like mtrw mentioned. sprintf() is meant for multiple scalar arguments of various types (it works w/ matrices, but not really in a clear way). num2str() is meant for use with a single matrix.

Jason S
+1  A: 

The closest I could come up with, is:

format bank

It will give you no E, and 2 decimal places.

try to read

help format

to look for other options there (I don't use Matlab anymore... switched to Free Software :) )

Ofri Raviv
Such as (Free Software?) ?
ldigas
Octave of course.
Ofri Raviv

related questions