How to replace diagonal of square matrices within a cell array?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Adnan Habib
le 11 Sep 2021
Commenté : Star Strider
le 13 Sep 2021
I have a 940X1 cell array where each element is a 298X298 square matrix. I want to replace the main diagonals of each square matrix with zero. Is there a way to do it?
0 commentaires
Réponse acceptée
Star Strider
le 11 Sep 2021
The easiest way is to subtract the diagonal of each matrix from the matrix —
C = {rand(4); rand(4); rand(4)}
Cr = cellfun(@(x) x-diag(x), C, 'Unif',0)
Cr{1}
Cr{3}
Make appropriate changes to get different results.
.
8 commentaires
Plus de réponses (0)
Voir également
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!