How to plot two lines in a looped subplot in matlab?
10 次查看(过去 30 天)
显示 更早的评论
I plotted 5 graphs with a loop in MATLAB. Now, I want to add a further line only to the third plot. However, when I try to do it, it adds the additional line to every subplot.
What I have is this:
lines = rand([30 5])
line2 = rand([30 1])
K =5
for j = 1:k
subplot(3, 2, j);
plot(lines(:,j), 'LineWidth',1,'Color', [0 0 0.5]);
hold on
plot(line2, 'LineWidth',1,'Color', [0 0 0.5], 'LineStyle','b--o')
yline(0, '-')
end
Can anyone help me out?
Thanks!
0 个评论
采纳的回答
Star Strider
2020-5-30
Add an if block in the loop:
lines = rand([30 5]);
line2 = rand([30 1]);
k = 5;
for j = 1:k
subplot(3, 2, j);
plot(lines(:,j), 'LineWidth',1,'Color', [0 0 0.5]);
hold on
if j == 3
plot(line2, 'LineWidth',1,'Color', [0 0 0.5], 'LineStyle','-.')
end
yline(0, '-')
end
.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Subplots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!