Modify matlab 2015 code to permanently change data tip precision
17 ビュー (過去 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..
0 件のコメント
採用された回答
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.
I hope this helps.
Kyle
2 件のコメント
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 Center および File Exchange で Creating and Concatenating Matrices についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!