Extracting matrix diagonal with diag(A)

3 ビュー (過去 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 Center および File ExchangeLogical についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by