cell matching
1 次查看(过去 30 天)
显示 更早的评论
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----
0 个评论
回答(3 个)
Walter Roberson
2011-10-17
ismember(c,b)
However that will not work if your version of MATLAB is sufficiently old. Which version are you using?
4 个评论
Walter Roberson
2011-10-18
Good question, I missed that. In that case,
ismember(c(~cellfun(@isempty,c)),b(~cellfun(@isempty,b)))
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)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Structures 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!