cell matching

4 visualizaciones (últimos 30 días)
Rusmaya Luthfina
Rusmaya Luthfina el 17 de Oct. de 2011
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----

Respuestas (3)

Walter Roberson
Walter Roberson el 17 de Oct. de 2011
ismember(c,b)
However that will not work if your version of MATLAB is sufficiently old. Which version are you using?
  4 comentarios
Walter Roberson
Walter Roberson el 18 de Oct. de 2011
Good question, I missed that. In that case,
ismember(c(~cellfun(@isempty,c)),b(~cellfun(@isempty,b)))
Jan
Jan el 18 de Oct. de 2011
@Walter: cellfun('isempty') is remarkably faster than cellfun(@isempty).

Iniciar sesión para comentar.


Fangjun Jiang
Fangjun Jiang el 17 de Oct. de 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 comentario
Rusmaya Luthfina
Rusmaya Luthfina el 18 de Oct. de 2011
actually, i'm programming document retrieval using vector space model, which between database and query must have same dimension.. :(

Iniciar sesión para comentar.


Rusmaya Luthfina
Rusmaya Luthfina el 18 de Oct. de 2011
i've been able to solve my problems.. :D thx u 4 your help!
---Maya--

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by