Filter löschen
Filter löschen

Retrieve Both Besides String of Center String

1 Ansicht (letzte 30 Tage)
Angga Lisdiyanto
Angga Lisdiyanto am 29 Jun. 2016
Kommentiert: José-Luis am 30 Jun. 2016
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.

Akzeptierte Antwort

José-Luis
José-Luis am 29 Jun. 2016
Bearbeitet: José-Luis am 29 Jun. 2016
data = {'a', 'b', 'c', 'o', 'm'};
idx = find(~cellfun(@isempty,strfind(data,'o')));
your_result = data(idx-1:idx+1)
  2 Kommentare
Angga Lisdiyanto
Angga Lisdiyanto am 29 Jun. 2016
Thanks.
By the way, what is difference of ~cellfun with cellfun?
José-Luis
José-Luis am 30 Jun. 2016
~ is the NOT operator.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Cell Arrays finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by