MATLAB: Matlab 2019b – bug in data tips accuracy

customdatatipsMATLABplotprecisionupdatefcn

Hi,
I'm using 2019b and I can't get the accurate value of a point in the graph using data tips.
Attached is an example.
Is there a way to fix this?
Thanks,
Gal

Best Answer

The values reported in the datatips are accurate, judging from the png image. Precision seems to be the issue, not accuracy. Note that your x and y axis ticks are x10^4. The reason the two x-values appear to be 77020 is probably because the data tips are not showing more precise values (ie, 77020.48930).
To change that, you could create a custom update function that specifies the precision to be reported. Here is a working demo below that you can easily adapt to your plotting function.
% Create a plot
clf()
ph = plot(magic(5).*7000+rand(1), 'o');
% Specify a custom update function to your data cursor object
dcm = datacursormode(gcf);
set(dcm, 'UpdateFcn', @customDataCursorUpdateFcn, 'Enable', 'On');
% Here's the function that specifies 5 decimal places
function txt = customDataCursorUpdateFcn(~, event)
pos = event.Position;
txt = {sprintf('X: %.5f', pos(1)), sprintf('Y: %.5f', pos(2))};
end % <- may not be needed