detecting TRUE elements of a cell array
19 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have a 12x3 cell array of logical vectors, as shown below:
[true; false] [false; false] [false; true]
[true; false] [false; true] [false; false]
true false false
false false true
true false false
true false false
[true; false] [false; false] [false; true]
true false false
[true; false] [false; false] [false; true]
true false false
[false; false] [true; false] [false; true]
[true; false] [false; true] [false; false]
I'd like to end up with two 12x3 matrices. The first matrix would be composed of 1 if all cell elements are TRUE or 0 otherwise for each element. The second matrix would consist of 1 if any cell elemnts are TRUE, 0 otherwise. For example, my the first six rows of the first matrix would look like this:
0 0 0
0 0 0
1 0 0
0 0 1
1 0 0
1 0 0
while the first six rows of the second matrix would look like this:
1 0 1
1 1 0
1 0 0
0 0 1
1 0 0
1 0 0
0 commentaires
Réponse acceptée
Azzi Abdelmalek
le 12 Déc 2012
Modifié(e) : Azzi Abdelmalek
le 12 Déc 2012
y={[true; false] false; false] [false; true]
[true; false] false; true] [false; false]
true false false
false false true}
out1= cellfun(@(x) all(x),y)
out2= cellfun(@(x) any(x),y)
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Data Types 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!