Clear Filters
Clear Filters

Retrieve Both Besides String of Center String

1 view (last 30 days)
Hi, i want to retrieve both string of center string. In example, i have below data :
data = {'a', 'b', 'c', 'o', 'm'}
center_string = {'c'}
Output
'b' 'o'
or
'b' 'c' 'o'
Thanks in advance.

Accepted Answer

José-Luis
José-Luis on 29 Jun 2016
Edited: José-Luis on 29 Jun 2016
data = {'a', 'b', 'c', 'o', 'm'};
idx = find(~cellfun(@isempty,strfind(data,'o')));
your_result = data(idx-1:idx+1)

More Answers (0)

Categories

Find more on Cell Arrays 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!