Afficher commentaires plus anciens
hi,
i have a code like this:
b = {'i'; 'need'; 'five'; 'rats'};
c = {'rats'; 'eat'; 'cheese'};
b{10} = [];
c{10} = [];
how do we match cell c with cell b?? i've tried using ismember but return error 'input must be array of string'
thank you,
---Maya----
Réponses (3)
Walter Roberson
le 17 Oct 2011
ismember(c,b)
However that will not work if your version of MATLAB is sufficiently old. Which version are you using?
4 commentaires
Fangjun Jiang
le 17 Oct 2011
Will you be able to run ismember(c,b) if both b and c contains empty elements, like after the OP's b{10}=[] and c{10} = [] statement?
Rusmaya Luthfina
le 18 Oct 2011
Walter Roberson
le 18 Oct 2011
Good question, I missed that. In that case,
ismember(c(~cellfun(@isempty,c)),b(~cellfun(@isempty,b)))
Jan
le 18 Oct 2011
@Walter: cellfun('isempty') is remarkably faster than cellfun(@isempty).
Fangjun Jiang
le 17 Oct 2011
Not sure why do you need to have the b{10}=[] and c{10} = [] statement. If it's allowed, you can set those elements to be empty string, and then run ismember().
b = {'i'; 'need'; 'five'; 'rats'};
c = {'rats'; 'eat'; 'cheese'};
b(end+1:10) = {''};
c(end+1:10) = {''};
ismember(b,c)
1 commentaire
Rusmaya Luthfina
le 18 Oct 2011
Rusmaya Luthfina
le 18 Oct 2011
0 votes
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!