How to find which column consists character 'example' in cell c{1,2}(:,1)

조회 수: 1 (최근 30일)
Terek Li
Terek Li 2016년 9월 30일
편집: dpb 2016년 9월 30일
so I have a cell called 'c', I want to know which column the characters 'example' exist in c{1,2}(:,1).... Is there a function that can do this? Or do I need to write my own loop?
What is the syntax for finding character within a cell?
Thanks

답변 (2개)

George
George 2016년 9월 30일
strcmp(c{1,2}(:,1), 'example')
will return a logical array. You may need to surround 'example' with cellstr(), I can't recall.

dpb
dpb 2016년 9월 30일
편집: dpb 2016년 9월 30일
So many possibilities of how things can be stored in cell arrays likely need a small example to see just what your arrangement actually is, but the following idiom is often useful...
s(~cellfun(@isempty,strfind(s,STRING)))
where s is the array and STRING is the target value looking for. The above returns those elements found;
ix=~cellfun(@isempty,strfind(s,STRING));
the indices into the cell array s the locations found containing STRING.
ADDENDUM
Is the following something like what you have, maybe?
>> c{2,1}='This is a string containing ''REPLACE'' within it'
c =
[]
'This is a string containing 'REPLACE' within it'
>> cellfun(@(s) strfind(s,'REPLACE'),c,'uniform',0)
ans =
[]
[30]
>>

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by