The # of signinficant digits in Matlab plot

  • MATLAB
  • Thread starter Useful nucleus
  • Start date
  • Tags
    Matlab Plot
In summary, when plotting a function in MATLAB, the y-axis values may be automatically rounded off to fewer significant digits. However, the XTickLabel property can be used to manually set the labels as strings and prevent this rounding.
  • #1
Useful nucleus
370
58
When I plot a function using MATLAB where the y-axis, for example, has values of : 1.8, 1.9, 2.0 , 2.1

Matlab ignores the number of siginficant digits when printing the value of 2.0, so it prints out:

1.8, 1.9, 2, 2.1

It there a way to change this?

Thank you in advance
 
Physics news on Phys.org
  • #2
XTickLabel is a property of the graph which you can set, and you can set it as strings so MATLAB doesn't automatically round the numbers off.

For example:

Code:
>> set(gca,'XTickLabel',{'1.8';'1.9';'2.0';'2.1';'2.2'})

The hassle is you have to type all the other ones as well, but it works. There might be a shortcut.
 
  • #3
Thank you very much! It worked!
 

1. How do I change the number of significant digits in a Matlab plot?

To change the number of significant digits in a Matlab plot, you can use the "format" function. For example, to display 3 significant digits, you can use the command "format short" before creating the plot. Alternatively, you can use the "sprintf" function to specify the number of significant digits in the format specifier.

2. Can I manually set the number of significant digits for each data point in a Matlab plot?

Yes, you can manually set the number of significant digits for each data point in a Matlab plot by using the "round" or "sprintf" functions. These functions allow you to specify the number of significant digits for each data point in the format specifier.

3. What is the default number of significant digits in a Matlab plot?

The default number of significant digits in a Matlab plot is 5. This means that all data points will be displayed with 5 significant digits unless otherwise specified using the "format" or "sprintf" functions.

4. How does changing the number of significant digits affect the accuracy of my Matlab plot?

Changing the number of significant digits in a Matlab plot only affects the display of the data points, not the actual accuracy of the plot. The original data points will not be altered, but the display may be rounded or truncated depending on the specified number of significant digits.

5. Can I change the number of significant digits in a Matlab plot after it has been created?

Yes, you can change the number of significant digits in a Matlab plot after it has been created by using the "format" or "sprintf" functions. Simply specify the desired number of significant digits and the plot will be updated accordingly.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
11
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
10
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
5K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
742
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
10
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
994
Back
Top