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

2 次查看(过去 30 天)
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.

采纳的回答

Walter Roberson
Walter Roberson 2013-9-21
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()

更多回答(0 个)

类别

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