accumarray error: Index into matrix must be positive

1 Ansicht (letzte 30 Tage)
Jack Ie
Jack Ie am 4 Apr. 2016
Bearbeitet: Walter Roberson am 4 Apr. 2016
G=[0 1 ; 0 2 ; 1 2];
adj=accumarray(G,1,[],[],0,true);
error: Index into matrix must be positive.

Akzeptierte Antwort

Star Strider
Star Strider am 4 Apr. 2016
What I do in situations such as yours is to add 1 to the minimum value (here 0) of the index array:
G=[0 1 ; 0 2 ; 1 2];
adj=accumarray(G+1,1,[],[],0,true);
That solves the immediate problem. You can make adjustments in other parts of your code afterwards.

Weitere Antworten (2)

Muhammad Usman Saleem
Muhammad Usman Saleem am 4 Apr. 2016

Chad Greene
Chad Greene am 4 Apr. 2016
The zeros in G are not positive.

Kategorien

Mehr zu Data Types finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by