Remove String and extract numbers to move to new column

2 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 String 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by