Remove String and extract numbers to move to new column

1 vue (au cours des 30 derniers jours)
Lukas Netzer
Lukas Netzer le 4 Août 2021
Commenté : Lukas Netzer le 4 Août 2021
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!

Réponse acceptée

Stephen23
Stephen23 le 4 Août 2021
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

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by