sparse and non-integers

Hi all, I'm trying to create a sparse matrix using the sparse function: sp=sparse(i,j,s)
but the vector j that I'm using consists of double values. This leads to the error:
??? Error using ==> sparse Index into matrix must be an integer.
I don't want to round my j vector cause this would lead to a distortion of the results I need from my dataset.
Is there a way to overcome this problem and finally construct the sparse matrix i need using the original j vector?
Thanks in advance jaso

답변 (2개)

Fangjun Jiang
Fangjun Jiang 2011년 8월 19일

0 개 추천

You don't have to modify j, just use
sp=sparse(i,round(j),s)
Walter Roberson
Walter Roberson 2011년 8월 19일

0 개 추천

No, there is not. Matrices cannot be indexed at non-integral values.
What value would you want returned if they could be indexed at non-integral values? Should A(3.2) be (8/10 * A(3) + 2/10 * A(4)) for example?
You should perhaps be considering using something like ismember() to map your floating point values to arbitrary integers.

카테고리

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

질문:

2011년 8월 19일

Community Treasure Hunt

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

Start Hunting!

Translated by