Error using subplot using for loops: subplot index too large
2 views (last 30 days)
Show older comments
The following command opens a blank (grey) figure window. It also opens subplot.m directly at the line:
error(message('MATLAB:subplot:SubplotIndexTooLarge'));
I followed advice related to this question and added the loopVar, but something is still incorrect.
How could I plot 16 subplots? (yA, yB and yC are 1x5 double variables)
Thanks!
loopVar=0;nVals1=4;rvals=5;
for val1idx=1:nVals1
for ivalue=1:4:12
figure(14)
indexplot=loopVar+ceil(ivalue/3);
subplot(nVals1,4,indexplot)
ystarIMr=mean(yA(val1idx,1:nVals2,:,ivalue),3);
plot(rvals,ystarIMr,'LineWidth',3,'LineStyle','-')
hold on
plot(rvals,mean(yB(val1idx,1:nVals2,:),3),'LineWidth',3,'LineStyle','--')
plot(rvals,mean(yC(val1idx,1:nVals2,:),3),'LineWidth',3,'LineStyle','-.')
end
loopVar = loopVar + val1idx;
end
0 Comments
Answers (1)
Steven Lord
on 18 Sep 2020
Set a conditional breakpoint on the line where you call subplot. The condition is nVals1*4 < indexplot. Run your code. When MATLAB stops at that breakpoint, what are the values of nVals1 and indexplot? Do those values make sense in the context of the underlying problem you're trying to solve with your MATLAB code?
If you have a 3-by-4 grid of subplots, where should subplot 13 be created?
See Also
Categories
Find more on Subplots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!