The # of signinficant digits in Matlab plot

  • Context: MATLAB 
  • Thread starter Thread starter Useful nucleus
  • Start date Start date
  • Tags Tags
    Matlab Plot
Click For Summary
SUMMARY

In MATLAB, when plotting functions, the software automatically rounds significant digits, resulting in values like 2.0 being displayed as 2. To maintain the desired number of significant digits, users can modify the XTickLabel property of the graph. By setting XTickLabel to a cell array of strings, such as {'1.8';'1.9';'2.0';'2.1';'2.2'}, MATLAB will display the specified values without rounding. This method requires manual entry of all tick labels but effectively preserves the formatting.

PREREQUISITES
  • Familiarity with MATLAB plotting functions
  • Understanding of graph properties in MATLAB
  • Basic knowledge of cell arrays in MATLAB
  • Experience with MATLAB command line interface
NEXT STEPS
  • Explore advanced MATLAB graph customization techniques
  • Learn about MATLAB formatting options for numerical output
  • Investigate the use of MATLAB's sprintf function for custom labels
  • Research MATLAB's documentation on XTick and XTickLabel properties
USEFUL FOR

Data scientists, engineers, and researchers who utilize MATLAB for data visualization and require precise control over numerical display in plots.

Useful nucleus
Messages
374
Reaction score
62
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
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.
 
Thank you very much! It worked!
 

Similar threads

  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 11 ·
Replies
11
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 1 ·
Replies
1
Views
5K
Replies
5
Views
3K
  • · Replies 11 ·
Replies
11
Views
5K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 10 ·
Replies
10
Views
3K
  • · Replies 2 ·
Replies
2
Views
4K