Borrar filtros
Borrar filtros

find the cell array contains a specific string

140 visualizaciones (últimos 30 días)
Yu Li
Yu Li el 28 de Nov. de 2018
Editada: Stephen23 el 28 de Nov. de 2018
I have a cell array as attached, I want to find the row number which contains a specified string, such as 'bore', I know how to write a for-loop to compare the element one by one, but, is there any easier way to do this?
Thanks!
Yu

Respuesta aceptada

Stephen23
Stephen23 el 28 de Nov. de 2018
Editada: Stephen23 el 28 de Nov. de 2018
Use strfind:
>> idc = strfind(file,'bore'); % search for 'bore' in all cells.
>> idx = ~cellfun('isempty',idc) % logical index, which cells contain 'bore'.
idx =
1
0
0
0
0
0
0
0
0
0
0
0
We can clearly see that the string in the first cell contains the pattern 'bore'. The indices in the cell array idc tell you where in the string/s that pattern was found.

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