Hello everyone,
does someone know how to write the value of the points in the x-axis? in my case, I got different periods and I want to write them in the X-axis,
the first one 0.5pi, second 1 pi, ..., the last one 8pi.
I'm thankful for every idea!

 採用された回答

Scott MacKenzie
Scott MacKenzie 2021 年 6 月 28 日
編集済み: Scott MacKenzie 2021 年 6 月 28 日

0 投票

If you want text labels with greek symbols, set the x ticks and x tick labels for the axis. Here's the general idea:
x = 0:0.5*pi:2*pi;
y = sin(x);
plot(x,y)
labels = {'0' '{\pi}/2' '{\pi}' '3{\pi}/2' '2{\pi}' };
set(gca,'xtick', x, 'xticklabels', labels);

3 件のコメント

Bruce Rogers
Bruce Rogers 2021 年 6 月 28 日
編集済み: Bruce Rogers 2021 年 6 月 28 日
Hello Scott,
this is exactly how I want the plot to look like, but it doesn't work on mine. Here's a part of the code:
p = zeros(1,5);
for i = 1:length(p)
p(1,i) = 0.25*2*pi;
p(2,i) = 0.5*2*pi;
p(3,i) = 1.0*2*pi;
p(4,i) = 2.0*2*pi;
p(5,i) = 4.0*2*pi;
end
figure(6)
plot(p,delta_s,'-o')
title('Grün: 0.2, Lila: 0.1, Gelb: 0.05, Rot: 0.025, Blau: 0.01')
labels = {'0' '{\pi}/2' '{\pi}' '3{\pi}/2' '2{\pi}' '5{\pi}/2' '3{\pi}' '7{\pi}/2' '4{\pi}' '9{\pi}/2' '5{\pi}' '11{\pi}/2' '6{\pi}' '13{\pi}/2' '7{\pi}' '15{\pi}/2' '8{\pi}'};
set(gca,'xtick', p, 'xticklabels', labels);
xlabel('Periodendauer')
ylabel('Differenz der Periodenmaxima')
legend('Blau: 100Hz','Rot: 40Hz','Gelb: 20Hz','Lila: 10Hz','Grün: 5Hz')
And that's the error message:
Error using matlab.graphics.axis.Axes/set
Value must be a numeric vector whose values increase.
Error in Einfluss_Abtastrate (line 622)
set(gca,'xtick', p, 'xticklabels', labels);
Scott MacKenzie
Scott MacKenzie 2021 年 6 月 28 日
Some minor tweaks...
n = 5;
p = zeros(1,n);
for i = 1:length(p)
p(1,i) = 0.25*2*pi;
p(2,i) = 0.5*2*pi;
p(3,i) = 1.0*2*pi;
p(4,i) = 2.0*2*pi;
p(5,i) = 4.0*2*pi;
end
delta_s = rand(1,5); % data added to avoid crash (change, as necessary)
figure(6)
plot(p,delta_s,'-o')
title('Grün: 0.2, Lila: 0.1, Gelb: 0.05, Rot: 0.025, Blau: 0.01')
labels = {'0' '{\pi}/2' '{\pi}' '3{\pi}/2' '2{\pi}' '5{\pi}/2' '3{\pi}' '7{\pi}/2' '4{\pi}' '9{\pi}/2' '5{\pi}' '11{\pi}/2' '6{\pi}' '13{\pi}/2' '7{\pi}' '15{\pi}/2' '8{\pi}'};
set(gca,'xtick', p(:,1), 'xticklabels', labels);
xlabel('Periodendauer');
ylabel('Differenz der Periodenmaxima');
legend('Blau: 100Hz','Rot: 40Hz','Gelb: 20Hz','Lila: 10Hz','Grün: 5Hz', ...
'location', 'southeast');
Bruce Rogers
Bruce Rogers 2021 年 6 月 28 日
Thanks for your help, thats perfect! :)

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeLabels and Annotations についてさらに検索

製品

リリース

R2020b

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by