Help with stem different colors

3 次查看(过去 30 天)
For my second plot my red lines keep coming up as red rings please help me with this clc; close all;
N=52;
x = zeros(1,N);
for n = 1:length(x)
x(n)= sin((n/16)*pi);
end
y= zeros(1,N);
y(1)=0;
for n = 2:length(x)-2
y(n+1)=(-1/3)*x(n+2)+(1/2)*x(n+1)+(1/3)*x(n)+y(n);
end
stem(0:1:51, y, 'r-');
xlabel('n');
ylabel('y[n]');
title('Output y[n] of the system');
pause;
z = conv(x,h);
stem(0:1:51, y, 'r-');
hold
stem(0:1:102, z, 'bo');
xlabel('n');
ylabel('z[n]');
title('z[n]');
legend('z[n]','y[n]');

采纳的回答

Star Strider
Star Strider 2017-12-3
If you just want the vertical lines without the markers:
stem(0:1:51, y, 'r-', 'Marker','none')
If you want the markers solid colours:
stem(0:51, y, 'bo', 'filled')
  2 个评论
Christopher Carey
Christopher Carey 2017-12-3
Hey this is just making my red plot not display at all I'm just seeing the blue.
Star Strider
Star Strider 2017-12-3
You need to specify different figures. Using hold is appropriate for the second plot.
figure(1)
stem(0:1:51, y, 'r-');
xlabel('n');
ylabel('y[n]');
title('Output y[n] of the system');
pause;
z = conv(x,h);
figure(2)
stem(0:1:51, y, 'r-');
hold on
stem(0:1:102, z, 'bo')
hold off
xlabel('n');
ylabel('z[n]');
title('z[n]');
legend('z[n]','y[n]')
If you want them all in the same plot, put hold on after the first plot instead, and remove the figure(2) line.
I did not specifically test this part of your code. It should work.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Line Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by