How to change the number of digits in a clabelm?
1 次查看(过去 30 天)
显示 更早的评论
Hello,
I need to change the number of digits in a clabelm.
Specifically, from 800000000000 to 8.00e+11.
Thanks
0 个评论
回答(1 个)
Anmol Dhiman
2020-1-30
Hello Christopher,
Unfortunately, ”clabelm” cannot be used directly to achieve this functionality.
Unfortunately MATLAB updates the text everytime the plot is redrawn - so you need to add a listener to update them each time that happens - hence why you listen for this particular event.
A possible workaround is to use the undocumented “MarkedClean” event to get the intended behavior as shown in below example.
function ScientificNotation
close all
figure;
[X,Y,Z] = peaks;
Z = Z*10000000000;
[C,h] = contourm(X, Y, Z,5,'ShowText','on');
% add a listener and call your new format function
addlistener(h,'MarkedClean',@(a,b)ReFormatText(a))
end
function ReFormatText(h)
textObj = findobj(h.Children,'Type','Text');
for i=1:size(textObj,1)
% get all the text items from the contour
t = textObj(i).String;
%for ii=1:length(t)
% get the current value (Matlab changes this back when it redraws the plot)
v = str2double(t);
% Update with the format you want - scientific for example
textObj(i).String = sprintf('%0.5e',v); % here it is specified as 0.2e
end
end
More information on how to specify the format can be found on the link below:
Please note that as MarkedClean is undocumented, the behavior of it might change in a future release of MATLAB.
Hope it Helps
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Argument Definitions 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!