MATLAB: Retrieve Both Besides String of Center String

cell arraycell arrays

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.

Best Answer

data = {'a', 'b', 'c', 'o', 'm'};
idx = find(~cellfun(@isempty,strfind(data,'o')));
your_result = data(idx-1:idx+1)