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

8 次查看(过去 30 天)
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.

采纳的回答

KSSV
KSSV 2022-2-24
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)

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Characters and Strings 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by