I am having an issue using strcmp when there is a single string in my cell array

2 visualizaciones (últimos 30 días)
Hello all!
I am having an issue using strcmp and I was wondering if maybe someone could help. I have a vector called L that looks like:
L = {'Aja',[],[],[],[], ... []};
with 46 empty entries. Then I have a list of words called U that looks like:
U = {string1, string2, ... ,'Aja', ..., stringN};
so U is a unique list of strings and the word in position L{1} is for sure in U, where in my case U{88} = 'Aja'. However when I do
strcmp(L,U{88})
returns a vector of 47 zeros. The first entry should for sure be one. Then when I do
strcmp(L{1},U{88})
it returns a 1 as it should. Does anyone know why this is happening? I need to be able to return the correct vector,
v = [1, 0 ,0 , 0 ...., 0];
Thank you for your help in advance.

Respuesta aceptada

Walter Roberson
Walter Roberson el 21 de Sept. de 2013
Use strcmp to compare each element in a cell array of strings to the corresponding element in a second cell array of strings.
So you are using it incorrectly. Perhaps you want ismember()

Más respuestas (0)

Categorías

Más información sobre Cell Arrays 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