cell matching

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----

回答(3 个)

ismember(c,b)
However that will not work if your version of MATLAB is sufficiently old. Which version are you using?

4 个评论

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?
i'm using R2010
Good question, I missed that. In that case,
ismember(c(~cellfun(@isempty,c)),b(~cellfun(@isempty,b)))
Jan
Jan 2011-10-18
@Walter: cellfun('isempty') is remarkably faster than cellfun(@isempty).

请先登录,再进行评论。

Fangjun Jiang
Fangjun Jiang 2011-10-17
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 个评论

actually, i'm programming document retrieval using vector space model, which between database and query must have same dimension.. :(

请先登录,再进行评论。

Rusmaya Luthfina
Rusmaya Luthfina 2011-10-18

0 个投票

i've been able to solve my problems.. :D thx u 4 your help!
---Maya--

类别

帮助中心File Exchange 中查找有关 Cell Arrays 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by