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 CenterFile Exchange에서 String에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by