Filter löschen
Filter löschen

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

8 Ansichten (letzte 30 Tage)
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.

Akzeptierte Antwort

KSSV
KSSV am 24 Feb. 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)

Weitere Antworten (0)

Kategorien

Mehr zu Characters and Strings 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