Displaying numbers in MATLAB


A colleague of mine asked me yesterday that he wanted to get more decimal places on some numerical computation he was carrying out in MATLAB. He was actually using the curve fitting toolbox to fit a custom function and obtain two parameters a and b, but he would get something like a=1.345, and he wanted to know at least two or three more decimal places. Typically the numeric information for these data is sitting in double precision in the MATLAB variables, however you have to know how to change the default format how MATLAB displays numbers to get it in the numeric format you want.

This post in the blog Loren on the Art of MATLAB explains the details. The short explanation is to use the format function. The default option is short, so if you write pi at the command line you get ans = 3.1416, but if you the write format long before calling pi, this time you get ans = 3.141592653589793. There are also other types of notation depending on what you need.

Advertisements

If you liked this post please leave a comment or consider subscribing.

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s