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 (최근 30일)
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)];

채택된 답변

MathWorks Support Team
MathWorks Support Team 2009년 6월 27일
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개)

카테고리

Help CenterFile Exchange에서 Sparse Matrices에 대해 자세히 알아보기

제품


릴리스

R14SP1

Community Treasure Hunt

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

Start Hunting!

Translated by