Extracting matrix diagonal with diag(A)

조회 수: 2 (최근 30일)
Irina
Irina 2015년 2월 19일
댓글: Irina 2015년 2월 19일
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.
>>

채택된 답변

Evan
Evan 2015년 2월 19일
편집: Evan 2015년 2월 19일
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
Irina
Irina 2015년 2월 19일
Thank you, that's exactly what happened.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Erik S.
Erik S. 2015년 2월 19일
Do you have another matrix in your workspace called diag?
  댓글 수: 1
Irina
Irina 2015년 2월 19일
Thank you, that's exactly what happened.

댓글을 달려면 로그인하십시오.

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by