How can I select a cell containing a specific text from a nx1 cell array and store it in a variable?

5 visualizaciones (últimos 30 días)
How can I select a cell containing a specific text from a nx1 cell array and store it in a variable?
a =
nx1 cell array
{'data1 = 231'}
{'line = 5457'}
{'data2 = a'}
{'sample = 889'}
{'ddf = 22'}
...
I want to make this result.
line =
1x1 cell
{'line = 5457'}
sample =
1x1 cell
{'sample = 889'}
I want to get a cell containing the text 'line, sample' without directly entering the index value.

Respuesta aceptada

KSSV
KSSV el 24 de Feb. de 2022
Read about contains, strcmp, strcmpi, strfind. All these functions give you index where theres is a match with the given input string.
If C is your nx1 cell array.
idx = contains(C,'line = 5457') ;
iwant = C(idx)

Más respuestas (0)

Categorías

Más información sobre Characters and Strings 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