Modify matlab 2015 code to permanently change data tip precision

15 次查看(过去 30 天)
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..

采纳的回答

Kyle
Kyle 2016-5-16
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.
For more information on modifying data tips, please refer to this documentation link .
I hope this helps.
Kyle
  2 个评论
Brian Wilmer
Brian Wilmer 2016-5-16
Great, thank you. I wasn't 100% if it was impossible to change the root subroutines. Thanks for confirming that and the code, I'll do that from here on out!
Minh Tran
Minh Tran 2018-7-31
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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by