extract cell depend on vector?
Afficher commentaires plus anciens
Dear all, I have vector a (1x7) and cell b (1x7), how can I extract each cell depend on elements equal in a?
a= [ 1 2 3 3 4 5 6 6];
b= { [1 2 3] [ 3 6] [ 5 6 7] [ 5 60] [ 5 6 5] [ 6 7 1 0] [ 88 99] [ 7 8 99] }
result should be:
res= {[ 5 6 7] [ 5 60] [ 6 7 1 0] [ 88 99]}
Thanks...
1 commentaire
Stephen23
le 7 Fév 2017
Why is [ 7 8 99] not in the output ?
Réponse acceptée
Plus de réponses (1)
>> a = [1,2,3,3,4,5,6,6];
>> b = {[1,2,3],[3,6],[5,6,7],[5,60],[5,6,5],[6,7,1,0],[88,99],[7,8,99]};
>> c = b(cellfun(@(v)~all(ismember(v,a)),b))
>> c{:}
ans =
5 6 7
ans =
5 60
ans =
6 7 1 0
ans =
88 99
ans =
7 8 99
4 commentaires
skysky2000
le 7 Fév 2017
skysky2000
le 7 Fév 2017
Guillaume
le 7 Fév 2017
Kudos to Stephen for figuring out what you want (maybe!) but really, you need to express yourself a lot clearer.
"There are only 4 elements equal in vector a"
4 elements equal to what?
skysky2000
le 7 Fév 2017
Modifié(e) : skysky2000
le 7 Fév 2017
Catégories
En savoir plus sur Cell Arrays dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!