Error using sparse. Index exceeds matrix dimensions.

조회 수: 12 (최근 30일)
Lujaina Abuerban
Lujaina Abuerban 2017년 1월 8일
댓글: Star Strider 2017년 1월 8일
I am trying to run this piece of code to do more operations on the graph G. However, I get the error cited in the title.
A = load('file.txt', '-ascii');
i = A(:,1);
j = A(:,2);
num = 11355;
G = sparse(i,j,1,num,num);
I am not sure if this is because sparse cannot make matrices that are in the order of magnitude of the prescribed matrix or this is a memory issue. I am relatively new to Matlab, so I am not sure what to do with it.
Thanks in advance.

답변 (1개)

Star Strider
Star Strider 2017년 1월 8일
I doubt if it’s a memory issue, since
G = sparse(num,num);
whos G
yields
Name Size Bytes Class Attributes
G 11355x11355 90864 double sparse
I would check to see if any elements of ‘i’ or ‘j’ are greater than ‘num’.
  댓글 수: 2
Lujaina Abuerban
Lujaina Abuerban 2017년 1월 8일
I traversed both 'i' and 'j' looking for their greatest elements, they yield 11354 and 11355 respectively. So, no, there are no elements greater than 'num'.
Star Strider
Star Strider 2017년 1월 8일
Oh, well.
You don’t have to scan them. Just use the max function.
A zero or a non-integer would throw a different error, so those aren’t the problem.

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

카테고리

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