Index exceeds matrix dimensions in very simple equation

조회 수: 4 (최근 30일)
shahin hashemi
shahin hashemi 2017년 12월 21일
답변: Birdman 2017년 12월 21일
x = sym('x', [1 3*N], 'real');
N=4;
L=1;
for i=2:N+1
pl(:,:,i)=L*[(cos(x(3*i-2))*(1-cos(x(3*i-1))))/x(3*i-1) (sin(x(3*i-2))*(1-cos(x(3*i-1))))/x(3*i-1) sin(x(3*i-1))/x(3*i-1)]';
end
dear all i dont understand why i get Index exceeds matrix dimensions error in this code
i really appreciated if you could help me

채택된 답변

Birdman
Birdman 2017년 12월 21일
When i=4, x(3*i-1) means you try to reach 13th element of x, but you defined its size as [1 12].
When i=5, x(3*i-1) and x(3*i-2) both try to reach 14th and 13th element of x, yet which is invalid.
Either change size of x, or change the value N accordingly.

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by