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

21 views (last 30 days)
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
returns a vector of 47 zeros. The first entry should for sure be one. Then when I do
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.

Accepted Answer

Walter Roberson
Walter Roberson on 21 Sep 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()

More Answers (0)

Community Treasure Hunt

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

Start Hunting!