Writing code to calculate number of ones & zeros in the logic matrix
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Ali Noori
le 27 Mai 2015
Commenté : Ali Noori
le 27 Mai 2015
Hi all, I'd like to write code to find number of ones & number of zeros ones respectively in logic matrix (1x34) attached below: I will be so grateful if someone help me. Best Regards

0 commentaires
Réponse acceptée
Plus de réponses (1)
Image Analyst
le 27 Mai 2015
If you have the Image Processing Toolbox, this is how you do it:
% Create sample data
A = [0,0,0,0,1,1,1,1,1,0,0,0,0,0,1,1,1,0,0,0,1,1,1,1,1,1,0,0,1,1,0,0,1,1]
% Label the 0's.
labeled0 = bwlabel(~A)
% Count the number of 0's.
measurements0 = regionprops(labeled0, 'Area');
% Label the 1's.
labeled1 = bwlabel(A)
% Count the number of 1's.
measurements1 = regionprops(labeled1, 'Area');
% Stitch together into a single matrix.
zeroAreas = [measurements0.Area]
onesAreas = [measurements1.Area]
bothAreas = [zeroAreas;onesAreas]
% Reshape into a row vector.
finalOutput = bothAreas(:)'
Voir également
Catégories
En savoir plus sur Multirate Signal Processing dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!