Plotting subplot with two concurrent plots

9 views (last 30 days)
I have two different graphs, which I would like to plot in a 2x5 subplot array.
I want the first 5 plots to be for graph1, and the bottom 5 plots to be for graph2, but this needs to all be in the same figure.
figure;
for k = 1:5
subplot(1,5,k);
[val,loca]=(max(abs(squeeze(S(1,k,:,:)))));
plot(T,squeeze(abs(S(1,k,92,:))),T,squeeze(abs(S(1,k,52,:)))); % graph1
legend('f1','f2')
title('Amplitude of f verses time')
ylabel('amplitude A.U')
xlabel('time (ns)')
end
figure;
for k = 1:5
subplot(1,5,k);
plot(T,F(loca),'m'); % graph2
title('Amplitude of f verses time')
ylabel('Frequency (Hz)')
xlabel('time (ns)')
legend('found F')
end
I need help with how to code so its all in one figure

Accepted Answer

Matt J
Matt J on 18 Mar 2019
Edited: Matt J on 18 Mar 2019
figure;
for k = 1:5
subplot(2,5,k);
[val,loca]=(max(abs(squeeze(S(1,k,:,:)))));
plot(T,squeeze(abs(S(1,k,92,:))),T,squeeze(abs(S(1,k,52,:)))); % graph1
legend('f1','f2')
title('Amplitude of f verses time')
ylabel('amplitude A.U')
xlabel('time (ns)')
end
for k = 1:5
subplot(2,5,k);
plot(T,F(loca),'m'); % graph2
title('Amplitude of f verses time')
ylabel('Frequency (Hz)')
xlabel('time (ns)')
legend('found F')
end
  1 Comment
Nnamdi Ohaka-Akpalaba
Nnamdi Ohaka-Akpalaba on 18 Mar 2019
Edited: Nnamdi Ohaka-Akpalaba on 18 Mar 2019
Thanks, that was nearly perfect
figure;
for k = 1:5
subplot(2,5,k);
[val,loca]=(max(abs(squeeze(S(1,k,:,:)))));
plot(T,squeeze(abs(S(1,k,92,:))),T,squeeze(abs(S(1,k,52,:)))); % graph1
legend('f1','f2')
title('Amplitude of f verses time')
ylabel('amplitude A.U')
xlabel('time (ns)')
end
for k = 6:10
subplot(2,5,k);
plot(T,F(loca),'m'); % graph2
title('Amplitude of f verses time')
ylabel('Frequency (Hz)')
xlabel('time (ns)')
legend('found F')
end
I just had to change the secong k loop to k = 6:10
This stopped the plots from overlapping

Sign in to comment.

More Answers (0)

Categories

Find more on Graphics Performance 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!