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!