Regular expression for 1*1 cell array

2 ビュー (過去 30 日間)
raghavendra kandukuri
raghavendra kandukuri 2019 年 9 月 26 日
編集済み: raghavendra kandukuri 2019 年 9 月 26 日
Hello,
I was trying to find the regular expression for a 1*1 cell array, the array looks somethig like this:
{'<string_attribute name="EEE_Level_LTT"><s>34</s></string_attribute>'}
I need just those numbers in the whole array, fox example its 34 in the above array, the charater array would be same every time, except those two or one digits.
Any help is higley appreciated.

採用された回答

Adam Danz
Adam Danz 2019 年 9 月 26 日
編集済み: Adam Danz 2019 年 9 月 26 日
Instead of a regular expression, you could use isstrprop() to identify which characters in each element of the cell array are digits and extract those digits. This assumes that there are no other digits in the char arrays other than those you'd like to extract.
'C' is an example cell array of chars.
'digits' is a numeric vector where digits(n) is the number stored in C{n}.
C(1) = {'<string_attribute name="EEE_Level_LTT"><s>34</s></string_attribute>'};
C(2) = {'<string_attribute name="EEE_Level_LTT"><s>9</s></string_attribute>'};
digits = str2double(cellfun(@(x)x(isstrprop(x,'digit')), C, 'UniformOutput',false));
  1 件のコメント
raghavendra kandukuri
raghavendra kandukuri 2019 年 9 月 26 日
Thank you @Adam, works perfectly.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Find more on Cell Arrays in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by