フィルターのクリア

How to re-scale an axis

146 ビュー (過去 30 日間)
Kristina
Kristina 2022 年 12 月 11 日
コメント済み: Star Strider 2022 年 12 月 12 日
I've been searching this community for this answer, but I don't believe what has been suggested to others helps in what I'm trying to accomplish.
The code I have does produce what I am looking to see in terms of a graph, but it sets the axis to the 6th power of 10. The original graph uses seconds. I am trying to rescale the horizontal axis so that it doesn't dictate it as 10 to the 6th. ylim, set gca, and caxis do not actually accomplish what I am trying to do. For reference I attached what my graph looks like and the black/white graph is what I am trying to accomplish. You can see one has a horizontal axis that only goes to 20 seconds (as its supposed to) but mine in the blue goes to 2,000,000. I thought the math worked out if I said this was in milliseconds but I have realized that doesn't make sense so please ignore the label on my graph that says (ms).

採用された回答

Star Strider
Star Strider 2022 年 12 月 11 日
Try something like this —
x = linspace(0, 2E6, 2E6);
y = sin(2*pi*x/1E6);
figure
plot(x, y)
figure
plot(x, y)
xt = get(gca, 'XTick');
set(gca,'XTickLabel',xt*1E-5)
The x-tick values are unchanged, however the x-tick labels have been re-scaled.
.
  2 件のコメント
Kristina
Kristina 2022 年 12 月 12 日
Thank you so much!
Star Strider
Star Strider 2022 年 12 月 12 日
As always, my pleasure!

サインインしてコメントする。

その他の回答 (1 件)

Image Analyst
Image Analyst 2022 年 12 月 11 日
So 2 million milliseconds is 2E-3 * 1E6 is 2E+3 seconds or 2000 seconds. So you can divide your x by 10^6 so that you get numbers in the 0 to 2 range and then just update your label:
plot(x/1E6, y, 'b-');
xlabel('Time (thousands of seconds)');

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by