Sparse Matrix Error

I've been trying to create a matrix using the sparse matrix command:
M=sparse(IndR,IndC,KP,S,S,4);
Where IndR, IndC and KP are vectors of size (4*S) times 1. S is about 700,000.
I get the following error when running the command:
??? Error using ==> sparse Index exceeds matrix dimensions.
I double checked and IndR and IndC only take values in the range 1:1:S. Any clues of what might be going on? Thanks!

 채택된 답변

John D'Errico
John D'Errico 2012년 5월 21일

0 개 추천

Read the help for sparse. What is that last argument? What does it say about nzmax?
For example, compare these two test cases:
>> sparse(1:5,1:5,1,5,5)
ans =
(1,1) 1
(2,2) 1
(3,3) 1
(4,4) 1
(5,5) 1
>> sparse(1:5,1:5,1,5,5,4)
Error using sparse
Index exceeds matrix dimensions.

추가 답변 (1개)

GeoM
GeoM 2012년 5월 21일

0 개 추천

Thanks John. Your example guided me to find the mistake. I was thinking of nzmax as the number of non-zeros in a row. It is the number of non-zeros in the whole matrix.

카테고리

도움말 센터File Exchange에서 Sparse Matrices에 대해 자세히 알아보기

태그

질문:

2012년 5월 21일

Community Treasure Hunt

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

Start Hunting!

Translated by