Using stem plot for two plots

26 ビュー (過去 30 日間)
Arkadius882
Arkadius882 2022 年 5 月 16 日
コメント済み: Voss 2022 年 5 月 16 日
I have very basic question regarding drawing stem plot for this example, it is supposed to have 21 data values.
T=4e-3; n=21;
x=linspace(0,T/2,2001);
x1=linspace(T/2,T,2001);
y=sin(pi*x/T);
y1=(1+cos(pi*x1/T));
plot(x,y,'b',x1,y1);
grid on; zoom on; hold on

採用された回答

Voss
Voss 2022 年 5 月 16 日
編集済み: Voss 2022 年 5 月 16 日
T=4e-3; n=21;
% x=linspace(0,T/2,2001);
% x1=linspace(T/2,T,2001);
x=linspace(0,T/2,(n+1)/2);
x1=linspace(T/2,T,(n+1)/2);
y=sin(pi*x/T);
y1=(1+cos(pi*x1/T));
% plot(x,y,'b',x1,y1);
stem(x,y,'b');
hold on
stem(x1,y1);
grid on; zoom on;
  5 件のコメント
Arkadius882
Arkadius882 2022 年 5 月 16 日
Thank you!
Voss
Voss 2022 年 5 月 16 日
You're welcome!

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

その他の回答 (1 件)

Steven Lord
Steven Lord 2022 年 5 月 16 日
This looks like a reasonable plot to me.
T=4e-3; n=21;
x=linspace(0,T/2,2001);
x1=linspace(T/2,T,2001);
y=sin(pi*x/T);
y1=(1+cos(pi*x1/T));
plot(x,y,'b',x1,y1);
grid on; zoom on; hold on
Let's plot it as a stem plot instead.
figure
stem([x,x1], [y,y1]);
There are too many stems to show each one as an individual line. Let's plot every 100 stems and see how that looks.
figure
stem([x(1:100:end), x1(1:100:end)], [y(1:100:end), y1(1:100:end)])
That looks nice to me.

カテゴリ

Help Center および File ExchangeStem Plots についてさらに検索

タグ

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by