Modify matlab 2015 code to permanently change data tip precision

조회 수: 17 (최근 30일)
Brian Wilmer
Brian Wilmer 2016년 5월 10일
댓글: Minh Tran 2018년 7월 31일
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