MATLAB Format and Display Precision Help


MATLAB does its internal arithmetic in IEEE floating point precision using approximately 16 decimal digits, but the default display is only 5 decimal digits, so do not be too concerned about the digits actually displayed as MATLAB output. The display can be changed from the default display (format short) to 15 digit display with exponent by the MATLAB command:
>> format long e
The loose display of output can be tightened up by the MATLAB command:
>> format compact
There are some more suboptions of the format command which you can find by
>> help format
(here ">> " is the MATLAB prompt in my session. If you want to display an output with other than 5 or 15 digits, than you have to use the formatted print command borrowed from the C programming language, for instance
>> b=12.12345678901234567;
>> fprintf('value of b is %1.10e\n',b)
value of b is 1.2123456789e+01
Here, "%n.me" is the exponential format for m digits after the decimal point ("n.mf" is for fixed point format), with much insensitivity to the "n" width of field parameter; "\n" means a line feed; anything else in quotes other than a format mask is taken as a literal string. Use
>> help fprintf
in MATLAB for more information. The C-like "sprintf" string print command behaves similarly. See also the MATLAB "disp" command with MATLAB "help" for quick and dirty printing out arrays:
>> help fprintf

Web Source: http://www.math.uic.edu/~hanson/MATLAB/MATLABformat.html

Email Comments or Questions to hanson@uic.edu