Remove String and extract numbers to move to new column

2 ビュー (過去 30 日間)
Lukas Netzer
Lukas Netzer 2021 年 8 月 4 日
コメント済み: Lukas Netzer 2021 年 8 月 4 日
I have a column like that:
WPS
"[0, 0]"
"[0, 5]"
"[5, 115]"
"[115, 219]"
"[219, 262]"
"[262, 328]"
"[328, 408]"
"[408, 424]"
"[424, 531]"
"[531, 562]"
Now for me to be able to further work with that, I would like to move the first and the second number in each of the strings to seperate new columns, which should look like that:
WP1 WP2
0 0
0 5
5 115
115 219
219 262
262 328
328 408
408 424
424 531
531 562
Now I found out that it somehow can be done with regular expressions, but I can not really figure out how. I'm thinking I need to use str2num but this would not work, as my string still contains brackets - any hint is appreciated - thank you!

採用された回答

Stephen23
Stephen23 2021 年 8 月 4 日
S = [...
"[0, 0]"
"[0, 5]"
"[5, 115]"
"[115, 219]"
"[219, 262]"
"[262, 328]"
"[328, 408]"
"[408, 424]"
"[424, 531]"
"[531, 562]"];
M = sscanf([S{:}],'[%f,%f]',[2,Inf]).'
M = 10×2
0 0 0 5 5 115 115 219 219 262 262 328 328 408 408 424 424 531 531 562

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeString についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by