Error using subplot using for loops: subplot index too large
显示 更早的评论
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
2020-9-18
0 个投票
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?
类别
在 帮助中心 和 File Exchange 中查找有关 Subplots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!