easy way to adjust axis labels to match x inputs

3 ビュー (過去 30 日間)
Christina
Christina 2024 年 8 月 30 日
編集済み: Christina 2024 年 8 月 30 日
Hello,
Does it need a for loop somehow?
I need the values on the x axis to show in radians, counting from 0 to 3pi, counting bu pi/20...
Graph is a simple cosine function

採用された回答

Walter Roberson
Walter Roberson 2024 年 8 月 30 日
I doubt that is what you really want.
figure
ax = gca;
x = 0:pi/20:3*pi;
y = cos(x);
plot(ax, x, y);
xticks(ax, x);
xticklabels( ax, string(0:1/20:3) + "\pi");
I think it more likely that you only want occasional axes labels.
figure
ax = gca;
x = 0:pi/20:3*pi;
y = cos(x);
plot(ax, x, y);
xt = x(1:10:end);
xticks(ax, xt);
xticklabels(ax, string(0:1/2:3) + "\pi")
  1 件のコメント
Christina
Christina 2024 年 8 月 30 日
編集済み: Christina 2024 年 8 月 30 日
Hello, thanks for offering feedback so fast. This bit of code is quite helpful. I'm in an intro to signals course right now and learning. Will make sure to credit new internet MatLab friends. The code I had was using xticks and xticklabels enumerating each tick mark, which ends up being cumbersome.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeAxis Labels についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by