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

10 visualizaciones (últimos 30 días)
Syed Waqas Ali
Syed Waqas Ali el 8 de Nov. de 2018
Respondida: Voss el 30 de Abr. de 2022
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 comentarios
jonas
jonas el 9 de Nov. de 2018
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 el 9 de Nov. de 2018
Funny! Yeah I closed MATLAB and started it again. Seems to work!
Thanks man!

Iniciar sesión para comentar.

Respuestas (1)

Voss
Voss el 30 de Abr. de 2022
'"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).

Categorías

Más información sobre Creating, Deleting, and Querying Graphics Objects en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by