Extract numbers from mixed string.

1 回表示 (過去 30 日間)
Jeong_evolution
Jeong_evolution 2016 年 10 月 29 日
コメント済み: Jeong_evolution 2016 年 11 月 3 日
Str = ['<data seq="0"<temp8.0</temp<data seq="1"<temp6.9</temp'];
I want to extract temp (8.0 & 6.9)
I want to express in workspace
-------------------------------
tem_1 = 8.0
tem_2 = 6.9
-------------------------------

採用された回答

Marc
Marc 2016 年 10 月 29 日
There are probably better ways to do this but if this is always going to be the string and only the numbers are going to change, you can use strfind() to get the locations of "temp"
Something like this:
xStr = strfind(Str, 'temp');
temp_1 = str2double(Str(xStr(1)+4:xStr(1)+6));
You should then be able to figure out temp_2....
  1 件のコメント
Jeong_evolution
Jeong_evolution 2016 年 11 月 3 日
Thank you.

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

その他の回答 (1 件)

per isakson
per isakson 2016 年 10 月 29 日
編集済み: per isakson 2016 年 10 月 29 日
Use regexp to match strings consisting of (digit,period,digit), and which follow after the string "temp"
Str = ['<data seq="0"<temp8.0</temp<data seq="1"<temp6.9</temp'];
cac = regexp( Str, '(?<=temp)\d\.\d', 'match' );
temp_2 = str2double(cac{2});
temp_1 = str2double(cac{1});
  1 件のコメント
Jeong_evolution
Jeong_evolution 2016 年 11 月 3 日
regexp function is good. Thanks!!

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

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by