Why is data cursor showing incorrectly approximated value in bar plot in MATLAB?

2 visualizaciones (últimos 30 días)
Below is the code:
Lw=[98.5321 98.5321 100.5321 92.5321 88.5321 81.5321 77.5321 75.5321];
bar(Lw)
Upon executing it I get a bar plot figure, which I have attached herewith. Upon using data cursor to point to the values, I see values approximated to one decimal as given below:
Lw=[98.5 98.5 101 92.5 88.5 81.5 77.5 75.5];
Observe that Lw(3) is specially displayed with incorrect approximation i.e 101 rather than 100.5(See the file attached). Why does this happen? Also, how to have data cursor to show values upto three decimals?
  2 comentarios
Walter Roberson
Walter Roberson el 19 de Oct. de 2016
Which MATLAB release are you using, and which operating system?
When I test just now R2016b on OS-X, I get the 100.5
Thanigaivel Raja T
Thanigaivel Raja T el 19 de Oct. de 2016
Thank you. I use R2013a on Windows 7. Is it due to OS / MATLAB?

Iniciar sesión para comentar.

Respuesta aceptada

Walter Roberson
Walter Roberson el 19 de Oct. de 2016
It is a matter of the number of characters. The display ends in 0.5 as expected on the values that are less than 100, where there is more room for characters. All of the items over 100 get rounded to not have the decimal point.
(Tested on R2012b on Windows 10)
  2 comentarios
Thanigaivel Raja T
Thanigaivel Raja T el 20 de Oct. de 2016
Thank you. Is there a way to increase the number of characters displayed? Because the bar plot is a display of result of a problem and part of a GUI. If the data cursor is inaccurate, then other methods for display of result need to be searched for.
Walter Roberson
Walter Roberson el 20 de Oct. de 2016
Have a look at datacursormode() which allows you to add a custom update function that can return any text.
101 showing up for 100.5321 is not actually wrong, it is rounding that goes on all the time. For example 100.5321 is itself rounded and in MATLAB would be represented as 100.5320999999999997953636921010911464691162109375 and I don't think you want all of that showing up (and if you do, get the File Exchange Contribution num2strexact(

Iniciar sesión para comentar.

Más respuestas (1)

Swarooph
Swarooph el 19 de Oct. de 2016
I looked at this on MATLAB R2016b and it looks ok.
In any case, play with the text update callback function to have custom decimal places/display. Documentation here.

Categorías

Más información sobre Environment and Settings en Help Center y File Exchange.

Productos

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by