How to solve the 'Index exceeds number of subplots' error?
84 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi guys, I have to solve this problem: I have this code:
for p=1:22
subplot(5,2,p)
end
It gives me the following error 'Index exceeds number of subplots', how can I solve it?
2 commentaires
the cyclist
le 14 Sep 2020
Please add more detail to this question. Or, better yet, ask a brand-new question the fully explains what you want to know.
Réponse acceptée
Jan
le 23 Jan 2018
Modifié(e) : Jan
le 23 Jan 2018
If you ask subplot to draw an 11th subplot on a 5 x 2 grid, you cannot expect that it is such smart to create a new figure and reset the index to 1. Matlab cannot simply do what you mean. But you can write a corresponding command.
for p = 1:22
pp = mod(p - 1, 10) + 1;
if pp == 1
FigH = figure;
end
subplot(5, 2, pp, 'Parent', FigH);
...
end
Plus de réponses (1)
the cyclist
le 23 Jan 2018
Modifié(e) : the cyclist
le 23 Jan 2018
The way you have defined the subplot layout, you have a 5-by-2 grid of subplots, which is a total of 10 subplot locations. But you are trying to place 22 subplots.
You need to increase the number of subplot locations (maybe use 5x5?), or decrease the number of subplots.
Voir également
Catégories
En savoir plus sur Subplots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!