How do I get all the plots to show over each other?

2 次查看(过去 30 天)
I tried using 'hold on' and 'hold off' but don't know where to place it.
samplingfrequencies = [5, 7, 8, 9, 20];
colors = 'bgrcm';
i = 1;
for n = samplingFrequencies
t = 0 : (1 / n) : 5;
y = sin(8 * t * (2 * pi));
subplot(5,1,i);
h = plot(t,y,colors(i));
set(h,'marker','*')
axis([0, 5, -1, 1]);
title([num2str(n), 'Hz Sample Rate']);
xlabel('time');
ylabel('amplitude');
i = i+1;
end

回答(1 个)

Rik
Rik 2018-5-24
Something like this maybe?
samplingfrequencies = [5, 7, 8, 9, 20];
colors = 'bgrcm';
i = 1;
for n = samplingFrequencies
t = 0 : (1 / n) : 5;
y = sin(8 * t * (2 * pi));
subplot(5,1,i);
hold on
h = plot(t,y,colors(i));
set(h,'marker','*')
axis([0, 5, -1, 1]);
title([num2str(n), 'Hz Sample Rate']);
xlabel('time');
ylabel('amplitude');
i = i+1;
end
hold off
  1 个评论
Rik
Rik 2018-5-27
Did this suggestion solve your problem? If so, please consider marking it as accepted answer. It will make it easier for other people with the same question to find an answer. If this didn't solve your question, please comment with what problems you are still having.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 2-D and 3-D Plots 的更多信息

标签

产品


版本

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by