How to Plot Multiple Plots with Multiple Subplots in Multiple Figures?
10 views (last 30 days)
Show older comments
Hello!
I've been trying to plot 5 graphs with the following breakdown on two seperate Figures:
- 4 graphs on FIGURE #1 as subplots of a 4x4 grid
- 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 Comments
jonas
on 9 Nov 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.
Answers (1)
Voss
on 30 Apr 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).
0 Comments
See Also
Categories
Find more on Creating, Deleting, and Querying Graphics Objects in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!