Is there a way to find number of blocks in a matrix?
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have a matrix that has 5 blocks along the diagonal and two consecutive blocks overlap in one diagonal element.
How can I compute the number of blocks in MATLAB?
3 commentaires
Réponse acceptée
Stephen23
le 15 Juin 2021
Modifié(e) : Stephen23
le 15 Juin 2021
Assuming that the blocks do not contain zeros:
A = [1,2,0,0,0,0,0,0,0;3,4,5,6,0,0,0,0,0;0,7,8,9,0,0,0,0,0;0,1,2,3,4,5,0,0,0;0,0,0,1,2,3,0,0,0;0,0,0,1,2,3,4,5,0;0,0,0,0,0,1,2,3,0;0,0,0,0,0,1,2,3,4;0,0,0,0,0,0,0,1,2]
[R,~] = find(diff(~A,1,1)>0);
N = 1+numel(unique(R))
If the blocks can contain zeros, then you will probably need to use some pattern matching.
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!