MATLAB Answers

checking of existing an string in a cell arrays

1.445 views (last 30 days)
There is a cell in name of 'CELL'. it is 1*12000 . its needed to check being and existing of a specified string in arrays of 'CELL'. so if the string doesn't exist do something
for example:
CELL={'a','b','c','d',...};
if 'a' not exists in CELL
do something
end

  0 Comments

Sign in to comment.

Accepted Answer

Lucas García
Lucas García on 21 Sep 2011
if ~any(strcmp(CELL,'a'))
% Do Something
else
% Do Something else
end

  4 Comments

Show 1 older comment
Lucas García
Lucas García on 21 Sep 2011
That will work. However, if you want to "do something" when the string 'a' is NOT found, you can just deny the previous commands:
if ~any(strcmp(CELL,'a'))
% Do something
end

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by