How to Plot Multiple Plots with Multiple Subplots in Multiple Figures?

조회 수: 13 (최근 30일)
Syed Waqas Ali
Syed Waqas Ali 2018년 11월 8일
답변: Voss 2022년 4월 30일
Hello!
I've been trying to plot 5 graphs with the following breakdown on two seperate Figures:
  1. 4 graphs on FIGURE #1 as subplots of a 4x4 grid
  2. 1 graph on FIGURE #2
I've used the following code, but I'm unable to do so as the 5th graph gets plotted in the first figure. In fact, there is no second figure generated no matter what I do. I've attached a screenshot of the figure generated:
% code
x = transmittedpower.FrequencyMHz;
tpower = transmittedpower.TransmittedpowerdBm;
bspower = transmittedpower.BackscatteredpowerdBm;
treadf = transmittedpower.Theoreticalreadrangeforwardm;
treadb = transmittedpower.Theroreticalreadrangereversem;
%FIRST FIGURE
figure;
h = gcf;
h.Color = 'white';
subplot(2,2,1);
plot(x,tpower, '*-');
xlabel('Frequency (MHz)');
ylabel('Transmitted Power (dBM)');
grid on;
subplot(2,2,2);
plot(x,bspower, '*-');
xlabel('Frequency (MHz)');
ylabel('Backscattered Power (dBM)');
grid on;
subplot(2,2,3);
plot(x,treadf, '*-');
xlabel('Frequency (MHz)');
ylabel('Theoretical read range forward (m)');
grid on;
subplot(2,2,4);
plot(x,treadb, '*-');
xlabel('Frequency (MHz)');
ylabel('Theoretical read range reverse (m)');
grid on;
%SECOND FIGURE (5th Graph)
figure
x2 = deg2rad(orientation.Angledeg);
y2 = db2mag(orientation.NormalizedradiationpatterndB);
polarplot(x2, y2, '*-');
I have also tried to number the figures, i.e. "figure(1)", "figure(2)", but doing so gives me an index out of range error, I'm not sure why.
Any help with getting this issue resolved would be highly appreciated.
Thanks, Regards, Syed Waqas Ali
  댓글 수: 2
jonas
jonas 2018년 11월 9일
That's odd. I ran your code with all variables set to 1, and got your desired output, i.e. one figure with 4 subplots and one figure with a single plot.
Syed Waqas Ali
Syed Waqas Ali 2018년 11월 9일
Funny! Yeah I closed MATLAB and started it again. Seems to work!
Thanks man!

댓글을 달려면 로그인하십시오.

답변 (1개)

Voss
Voss 2022년 4월 30일
'"figure(1)", "figure(2)" ... gives me an index out of range error'
That error happens when indexing a variable, which means that you had a variable called figure in your workspace. In that situation, figure refers to the variable rather than the function figure, so you can't create new figures with the figure function until the figure variable is cleared (restarting MATLAB clears all the variables).

카테고리

Help CenterFile Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by