MATLAB Figure Horizontal Precision
2 次查看(过去 30 天)
显示 更早的评论
I'm creating a figure with a large timescale in MATLAB. The numbers I'm using go down to milliseconds and the full range is in thousands of seconds.
By default, when I plot a figure, it's giving me scientific notation on the time with 4 decimal points, e.g. 4.400 and has x10^4 on the right. When I zoom in on the figure, the precision of the horizontal axis labels does not change. When I'm zoomed in really far, I get multiple labels all with the same number (e.g. 4.401, 4.401, 4.401, 4.401) so I can't tell the time difference in the points I'm looking at. How can I set the precision out to more decimal places?
I've tried:
xlbl = get(gca,'XTickLabel');
set(gca,'XTickLabel',sprintf('%16.6f',xlbl));
But all that does is add zeros the existing labels.
I tried
set(gca,'XTickLabel',sprintf('%6.6f',myarray(:,1))
where myarray(:,1) are the time values, but that freezes up because it's too many labels, and even if it worked it wouldn't give me what I want when I'm zoomed out.
format long
did nothing for the figure, only the command window.
Also, I need to be able to use the interactive Zoom in/Zoom out tools in the MATLAB figure window. If I use set(gca,'XTickLabel',....), even if I got it to display what I wanted, that's giving me fixed labels that have to be updated each time and would turn this into a science project.
Any suggestions?
0 个评论
回答(1 个)
Star Strider
2014-9-26
You likely need to get the 'XTick' values themselves, then use 'XTickLabel' to display them. This code works, but I don’t know if it will do what you want. Note that I divided the values by 1E+4 to eliminate formatting problems:
x = linspace(0, 2*pi*1E+4, 1000);
y = sin(x/1E+4)+cos(x/1E+4);
figure(1)
plot(x, y)
xtk = get(gca, 'XTick');
set(gca, 'XTickLabel', strsplit(sprintf('%10.7f ', xtk/1E+4)))
You will need the strsplit function to make it work correctly.
2 个评论
Star Strider
2014-9-26
I thought it did rescale when I tried it on my test code.
I don’t have your data so I can’t test it to see how to solve your problem specifically.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Exploration 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!