How to display with n decimal places in matlab

I was wondering how to use the command to configure the display with n decimal places in Matlab?

Should I be limited to some predefined numbers? Or can you just specify any for n?

Thank you and welcome!

+8
matlab number-formatting
source share
3 answers

You can convert a number to a string with n decimal places using the SPRINTF command :

 >> x = 1.23;
 >> sprintf ('% 0.6f', x)

 ans =

 1.230000

 >> x = 1.23456789;
 >> sprintf ('% 0.6f', x)

 ans =

 1.234568
+9
source share

This site can help you with this:

http://herz-fischler.ca/MATLAB/section15.html

+4
source share

I use tim say sprintf('%0.6f', x) , this is a string, then I change it to a number using the str2double(x) command.

-2
source share

All Articles