MATLAB Answers

0

Extracting matrix diagonal with diag(A)

Irina 님이 질문을 제출함. 19 Feb 2015
최근 활동 Irina 님이 댓글을 추가함. 19 Feb 2015
A simple function that used to run now gives an error message. What am I doing wrong?
>> a = eye(4,4);
>> diag(a)
Subscript indices must either be real positive integers or logicals.
>>

  댓글 수: 0

로그인 to comment.

태그

답변 수: 2

Evan 님의 답변 19 Feb 2015
Evan 님이 편집함. 19 Feb 2015
 채택된 답변

Does this fix your problem?
a = eye(4,4) == 1;
diag(a)
While the diag function works fine, if you have a variable named diag (not a good idea--give it a unique name that isn't the same as a builtin function), it expects a logical, not double, input for indexing.

  댓글 수: 1

Thank you, that's exactly what happened.

로그인 to comment.


Erik S. 님의 답변 19 Feb 2015

Do you have another matrix in your workspace called diag?

  댓글 수: 1

Thank you, that's exactly what happened.

로그인 to comment.



Translated by