cell matching

조회 수: 9 (최근 30일)
Rusmaya Luthfina
Rusmaya Luthfina 2011년 10월 17일
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개)

Walter Roberson
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
Walter Roberson 2011년 10월 18일
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
Rusmaya Luthfina
Rusmaya Luthfina 2011년 10월 18일
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일
i've been able to solve my problems.. :D thx u 4 your help!
---Maya--

카테고리

Help CenterFile Exchange에서 Cell Arrays에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by