Modify matlab 2015 code to permanently change data tip precision
17 views (last 30 days)
Show older comments
I want to do this http://www.mathworks.com/matlabcentral/newsreader/view_thread/343639 but I was wondering if there was a modify the main matlab code like versions before 2014? I'm also not sure how to implement the code in that example for all of my graphs. Do i need that for each figure? It would be much nicer to just tweak the main matlab subroutine..
0 Comments
Accepted Answer
Kyle
on 16 May 2016
Hi Brian,
As of R2014b there is no way to set the default data tip precision. Thus, you will need to change the datacursormode options for each of your figures. However, if you wish to change all data tips for your graphs in the same way, you can define one function to serve as the UpdateFcn for all of your figures.
For example, if you wish to display five decimal places on each graph's data tip, your code might look something like this:
fig1 = figure;
surf(peaks);
fig2 = figure;
plot([1:0.1:10], [1:0.1:10]);
dcm1 = datacursormode(fig1);
set(dcm1, 'UpdateFcn', @myUpdateFcn, 'Enable', 'on');
dcm2 = datacursormode(fig2);
set(dcm2, 'UpdateFcn', @myUpdateFcn, 'Enable', 'on');
function outText = myUpdateFcn(obj, event)
pos = get(event, 'Position');
if length(pos) == 3
outText = {sprintf('X: %.5f', pos(1), ...
sprintf('Y: %.5f', pos(2), ...
sprintf('Z: %.5f', pos(3)};
else
outText = {sprintf('X: %.5f', pos(1), ...
sprintf('Y: %.5f', pos(2)};
end
end
This code will change your data tips to show five decimal places. You can change this number by modifying the number in the %.5f portion of the sprintf function.
I hope this helps.
Kyle
2 Comments
Minh Tran
on 31 Jul 2018
Thanks. I had to call myUpdateFcn from a separate .m file and call datacursormode (and datacursormode.UpdateFcn) from the main execution but it works on 2015b.
More Answers (0)
See Also
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!