Extracting matrix diagonal with diag(A)
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Akzeptierte Antwort
Evan
am 19 Feb. 2015
Bearbeitet: Evan
am 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.
Weitere Antworten (1)
Siehe auch
Kategorien
Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!