Effacer les filtres
Effacer les filtres

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

8 vues (au cours des 30 derniers jours)
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.

Réponse acceptée

KSSV
KSSV le 24 Fév 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)

Plus de réponses (0)

Catégories

En savoir plus sur Characters and Strings dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by