Error using subplot using for loops: subplot index too large

1 次查看(过去 30 天)
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

回答(1 个)

Steven Lord
Steven Lord 2020-9-18
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?
  2 个评论
Orangina
Orangina 2020-9-18
Thanks for your reply.
val1idx=nVals1=4 and indexplot=9. LoopVar=10 and ceil(ivalue/3)=3, so it seems that indexplot=13 should be the next step. I do not understand why it stops since the aim is that indexplot should be able to go up to 16. AT face value, I don't see how to make sense of this error with regards to the plots I want to make.
Subplot 13 would only be created if one extends the grid to 4-by-4. But I don't see how it relates to my current problem, maybe I missed something but I put a 4-by-4 grid for 16 subplots.
Do you have any idea why the 9 subplots that are now created are empty?

请先登录,再进行评论。

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by