필터 지우기
필터 지우기

Index exceeds matrix dimensions.

조회 수: 2 (최근 30일)
Sara
Sara 2012년 6월 20일
for the code below I received the error index exceeds.. I do not know how can I fix it.
x = zeros( 2,length(v0) ) ;
for k = 1:length(v0)
A = [ factor1(:,k) factor2(:,k)];
b = -rhs(:,k);
x(:,k) = A\b ;
//end of for
length v0 = 2501
A\b is 2 by 2 matrix but x(:,k) is 2 by 2501.
  댓글 수: 3
Sara
Sara 2012년 6월 20일
the sizes of factor1 and factor2 are 2 by 2501.
by the line x (:,k) = A\b , it has error.
Walter Roberson
Walter Roberson 2012년 6월 20일
That doesn't sound like an "index exceeds" error, that sounds like an error about RHS having more non-singleton dimensions than the LHS has.
Please show the exact error.
If A\b is a 2 x 2 matrix, then were you only expecting a 2 x 1 matrix as the result of the A\b operation? Or you only care about one of the rows or one of the columns? Or you want to store all 4 results and do that in a single column ?

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

답변 (1개)

per isakson
per isakson 2012년 6월 20일
Do you use the debugger?
  1. Put a break on the line that causes the error or
  2. Tools | Debug | Stop if Error
  3. Run the code
  4. At the break inspect the values of the index
  댓글 수: 2
Walter Roberson
Walter Roberson 2012년 6월 20일
A zero index would generate the error about indices needing to be positive integers, not the error about exceeding matrix dimensions.
per isakson
per isakson 2012년 6월 20일
Thanks Walter; fixed. I try to make the point that better asking the debugger than Answer.

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

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by