Extracting matrix diagonal with diag(A)

2 visualizaciones (últimos 30 días)
Irina
Irina el 19 de Feb. de 2015
Comentada: Irina el 19 de Feb. de 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.
>>

Respuesta aceptada

Evan
Evan el 19 de Feb. de 2015
Editada: Evan el 19 de Feb. de 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 comentario
Irina
Irina el 19 de Feb. de 2015
Thank you, that's exactly what happened.

Iniciar sesión para comentar.

Más respuestas (1)

Erik S.
Erik S. el 19 de Feb. de 2015
Do you have another matrix in your workspace called diag?
  1 comentario
Irina
Irina el 19 de Feb. de 2015
Thank you, that's exactly what happened.

Iniciar sesión para comentar.

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by