Borrar filtros
Borrar filtros

Retrieve Both Besides String of Center String

1 visualización (últimos 30 días)
Angga Lisdiyanto
Angga Lisdiyanto el 29 de Jun. de 2016
Comentada: José-Luis el 30 de Jun. de 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.

Respuesta aceptada

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

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Cell Arrays en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by