Why do I receive an error message saying: “??? Index exceeds matrix dimensions. Error in ==> spdiags at 114” when using the SPDIAGS function to create a 2-by-1 sparse matrix from a null matrix in MATLAB?
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
When I execute the following command to create a 2-by-1 sparse matrix from the columns of a null matrix ([]):
spdiags([], 0, 2,1)
I expect MATLAB to return an empty matrix, but I receive the following error message:
??? Index exceeds matrix dimensions.
Error in ==> spdiags at 114
a((len(k)+1):len(k+1),:) = [i i+d(k) B(i+(m>=n)*d(k),k)];
Réponse acceptée
MathWorks Support Team
le 27 Juin 2009
This is expected behavior in MATLAB. The SPDIAGS function results in an error message saying: "??? Index exceeds matrix dimensions." if the number of rows in the matrix B [ in the syntax "A = spdiags(B,d,m,n)" ] is less than the length of the diagonal of the sparse matrix to be created. Consider the following example:
A = spdiags([1 2], [0 1], 1, 2) % This is correct syntax as number_of_rows(B) = length_of_diagonal(A)
However, the following code would result in the error message:
A = spdiags([1 2], [0 1], 2, 2) % This is incorrect syntax as number_of_rows(B) < length_of_diagonal(A) which is 2
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Sparse Matrices dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!