I am having an issue using strcmp when there is a single string in my cell array
9 views (last 30 days)
Show older comments
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.
0 Comments
Accepted Answer
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()
0 Comments
More Answers (0)
See Also
Categories
Find more on Characters and Strings in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!