Clear Filters
Clear Filters

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

2 views (last 30 days)
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

Answers (1)

Rik
Rik on 24 May 2018
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 Comment
Rik
Rik on 27 May 2018
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.

Sign in to comment.

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Products


Release

R2018a

Community Treasure Hunt

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

Start Hunting!