How to overcome the error message in the script below -Matrix dimension error - due to different size array manipulation

조회 수: 1 (최근 30일)
How to overcome the error message in the script below;
m=4;
PT_mj=[0 0.01 0.02 0.03
0 0 0.045 0.05
0 0 0 0.06];
PT_jm=PT_mj' ;
flr_jm=zeros(4,3);
for i=2:m
for j=1:(m-1)
if j~=i
if i~=(m-2) | j~=(m-1)
deltalambda_2(i)=PT_mj(i,j)-(1-flr_jm(i,j))*PT_jm(i,j)
end
end
end
end
  댓글 수: 1
Jan
Jan 2012년 7월 5일
편집: Jan 2012년 7월 5일
Please post the complete error message and mention, which line causes the error. I currently do not see a problem, which could cause the (partially) posted message. Please edit the original message and do not provide the additional information as comment or answer.
Please choose a short title, and include all information required to understand the problem, in the body of the question. Thanks.

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

답변 (2개)

Mark Whirdy
Mark Whirdy 2012년 7월 5일
Hi there problem is with
i=2:m
m here is 4, but the size of PT_mj is [3,4] so the matrix access below won't work
PT_mj(i,j)
What are you trying to do generally? (if its not recursive we can do it without loops probably) Mark
  댓글 수: 1
Jan
Jan 2012년 7월 5일
편집: Jan 2012년 7월 5일
I do not understand, why "i=2:m" should cause troubles here. Could you elaborate this? The error message does not belong to an out-of-range indexing.

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


Mark Whirdy
Mark Whirdy 2012년 7월 7일
Hi Jan
The error I get is
??? Index exceeds matrix dimensions.
Since PT_mj is a [3*4] matrix and we are trying to access PT_mj(i,j) where i =4, I get this error. I take it you're getting a different error then?
Changing
deltalambda_2(i)=PT_mj(i,j)-(1-flr_jm(i,j))*PT_jm(i,j)
to
deltalambda_2(i)=PT_jm(i,j)-(1-flr_jm(i,j))*PT_jm(i,j)
prevents the error, but since I can't get my head around the intended behaviour of the code I doubt if this is really a fix. Especially since with this "fix, " deltalambda_2 is now all zeroes, and that line could be further resolved to
deltalambda_2(i)=flr_jm(i,j)*PT_jm(i,j)
which is a kind of unlikely trivial simplification unless the algorithm is totally misspecified. Without understanding more fully the context, I can't make any progress myself. Maybe you'll have more luck.

카테고리

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