Effacer les filtres
Effacer les filtres

How do you extract diagonal elements of a cell array?

14 vues (au cours des 30 derniers jours)
LL
LL le 14 Jan 2022
Commenté : LL le 14 Jan 2022
[9;9;9;9;1;1;2;2] [9;2;1;1;2;1;9;9] [9;2;1;1;2;1;9;9]
[9;9;9;9;1;1;2;2] [9;2;1;1;2;1;9;9] [9;2;1;1;2;1;9;9]
0 [2;1;9;2;9;9;9;9] [2;1;9;2;9;9;9;9]
Hi, need help:
i have a cell array like this one, and i need to extract only the elements on the diagonal how can i do?
Please advise Thanks!

Réponse acceptée

Max Heimann
Max Heimann le 14 Jan 2022
Modifié(e) : Max Heimann le 14 Jan 2022
Assuming your matrix "data" is equal in x and y dimension:
[y,x] = size(data)
selected_values = data([1:y+1:x*y])
Alternatively you could try creating an index matrix with the "eye" command and then use that to select your values from the matrix.
  1 commentaire
LL
LL le 14 Jan 2022
Super it works correctly!!
Thank you ;)

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Operating on Diagonal Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by