필터 지우기
필터 지우기

How to solve the 'Index exceeds number of subplots' error?

조회 수: 41 (최근 30일)
Emrys
Emrys 2018년 1월 23일
댓글: the cyclist 2020년 9월 14일
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
Iqra Jabeen
Iqra Jabeen 2020년 9월 13일
how to solve 2*5 grid subplot
the cyclist
the cyclist 2020년 9월 14일
Please add more detail to this question. Or, better yet, ask a brand-new question the fully explains what you want to know.

댓글을 달려면 로그인하십시오.

채택된 답변

Jan
Jan 2018년 1월 23일
편집: Jan 2018년 1월 23일
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

추가 답변 (1개)

the cyclist
the cyclist 2018년 1월 23일
편집: the cyclist 2018년 1월 23일
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.
  댓글 수: 1
Emrys
Emrys 2018년 1월 23일
편집: Emrys 2018년 1월 23일
Is there any way of automatically creating new layouts? what I was expecting were three figures, 2 with 10 elements and one with 2 .

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Subplots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by