Dividing the string data

1 回表示 (過去 30 日間)
SungMin Park
SungMin Park 2021 年 3 月 22 日
コメント済み: SungMin Park 2021 年 3 月 25 日
68753-9.990e+000 -9.900e-002 -9.990e-003-3.330e+000의 string을
68753 -9.990e+000 -9.900e-002 -9.990e-003 -3.330e+000처럼 데이터를 나누고 싶습니다.
그런데 구분자를 ' '로하면 68753-9.990e+000이 나누어 지지 않습니다.
그리고 구분자를 ' '와 '-'로 하면 -9.990e-003이 나누어 집니다.
이런 상황에서는 어떻게 데이터를 처리하면 좋을까요?

採用された回答

Rik
Rik 2021 年 3 月 22 日
You can split this with a regular expression.
str='68753-9.990e+000 -9.900e-002 -9.990e-003-3.330e+000';
RE=['[+-]?',... %start with an optional + or -
'[.\d]*',... %then the number itself: only digits or periods
'(e[+-]\d*)?'];%optionally followed by e with either + or - and several digits
nums=regexp(str,RE,'match')
nums = 1×5 cell array
{'68753'} {'-9.990e+000'} {'-9.900e-002'} {'-9.990e-003'} {'-3.330e+000'}
You can even send this result to str2double to convert them to their numeric values:
str2double(nums)
ans = 1×5
1.0e+04 * 6.8753 -0.0010 -0.0000 -0.0000 -0.0003
  1 件のコメント
SungMin Park
SungMin Park 2021 年 3 月 25 日
thank you ^^

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

その他の回答 (0 件)

カテゴリ

Help Center および File Exchange데이터형 변환 についてさらに検索

Community Treasure Hunt

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

Start Hunting!