Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible in matlab to explicitly format the output numbers?

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.

like image 909
Rook Avatar asked Nov 28 '22 11:11

Rook


2 Answers

According to the Matlab documentation which is available on their website you can use

format shortG

to set the display format for the output to n.4.

like image 34
trondd Avatar answered Dec 10 '22 12:12

trondd


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.

like image 77
mtrw Avatar answered Dec 10 '22 11:12

mtrw