Wednesday, April 8, 2015

[MATLAB] Search a string within a string cell array

my MATLAB version : R2012b


If you want to check whether a word is listed in a cell array of strings,

cellAry = {'hello', 'young', 'archive', 'blog'};
strin    = 'young';

# 1
idx = strfind( cellAry, strin );                     % The result is logical
idx = find( ~cellfun(@isempty, idx) );         % Find '1' indices which are only '1'


# 2
idx = find( ismember( cellAry, strin ) );


# 3
idx = find( strcmp( cellAry, strin ) );

No comments:

Post a Comment