Using stem plot for two plots

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

 Respuesta aceptada

Voss
Voss el 16 de Mayo de 2022
Editada: Voss el 16 de Mayo de 2022
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 comentarios

Or
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(x1,y1,'Color',[0.85 0.325 0.098]);
hold on
stem(x,y,'b');
grid on; zoom on;
Arkadius882
Arkadius882 el 16 de Mayo de 2022
This one works which I'm very thankful of, but the plot should also be visible. I've been trying to connect these two but the plot must be drawn few thousand times (academic task) and because of that vectors are not the same length, at least it sounds like it to me.
T=4e-3; n=21;
x=linspace(0,T/2,2001);
xd=linspace(0,T/2,(n+1)/2);
x1=linspace(T/2,T,2001);
xd1=linspace(T/2,T,(n+1)/2);
y=sin(pi*x/T);
y1=(1+cos(pi*x1/T));
plot(x,y,'b',x1,y1);
grid on; zoom on; hold on;
stem(xd,y,'r*');
stem(xd1,y1,'r*');
T=4e-3; n=21;
x=linspace(0,T/2,2001);
xd=linspace(0,T/2,(n+1)/2);
x1=linspace(T/2,T,2001);
xd1=linspace(T/2,T,(n+1)/2);
y=sin(pi*x/T);
yd=sin(pi*xd/T);
y1=(1+cos(pi*x1/T));
yd1=(1+cos(pi*xd1/T));
plot(x,y,'b',x1,y1);
grid on; zoom on; hold on;
stem(xd,yd,'r*');
stem(xd1,yd1,'r*');
Arkadius882
Arkadius882 el 16 de Mayo de 2022
Thank you!
Voss
Voss el 16 de Mayo de 2022
You're welcome!

Iniciar sesión para comentar.

Más respuestas (1)

Steven Lord
Steven Lord el 16 de Mayo de 2022
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.

Categorías

Más información sobre Data Exploration en Centro de ayuda y File Exchange.

Productos

Versión

R2022a

Etiquetas

Preguntada:

el 16 de Mayo de 2022

Comentada:

el 16 de Mayo de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by