フィルターのクリア

find numbers in a string

23 ビュー (過去 30 日間)
EYAL COHEN
EYAL COHEN 2023 年 7 月 25 日
移動済み: Bruno Luong 2023 年 7 月 25 日
Hi,
I have the following example of string 'E_Field (Farfield) (Cartesian) (-0 -1000 -1)(Abs) (cosim Tran1).txt' .
I need to extract the numbers between the brackets 0,1000,-1.
I have tried using the regexp function but without any success.
I will appriciate any kind of assistance.

回答 (1 件)

Chunru
Chunru 2023 年 7 月 25 日
編集済み: Chunru 2023 年 7 月 25 日
s = 'E_Field (Farfield) (Cartesian) (-0 -173.648 983.808)(Abs) (cosim Tran1).txt';
s1 = 'E_Field (Farfield) (Cartesian) (-0 -1000 -1)(Abs) (cosim Tran1).txt' ;
p = '(\(-?\d+ -?\d+(.\d*)? -?\d+(.\d*)?\))';
t=regexp(s, p, 'tokens');
t = t{1}{1}
t = '(-0 -173.648 983.808)'
n = sscanf(t, '(%f %f %f)')
n = 3×1
0 -173.6480 983.8080
t1=regexp(s1, p, 'tokens');
t1 = t1{1}{1}
t1 = '(-0 -1000 -1)'
n1 = sscanf(t1, '(%f %f %f)')
n1 = 3×1
0 -1000 -1
  5 件のコメント
Chunru
Chunru 2023 年 7 月 25 日
See above
EYAL COHEN
EYAL COHEN 2023 年 7 月 25 日
移動済み: Bruno Luong 2023 年 7 月 25 日
It seems to work, I thank you for your help. A big help.

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

カテゴリ

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

製品


リリース

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by