How to extract values from a string.
조회 수: 16 (최근 30일)
이전 댓글 표시
So I have a string in the following format:
filename = "Delft_2_220_20_4344-5088.csv" ;
And I want to extract the numbers from it, what is a good way to do this?
So the result is something like this:
a=2; b=220; c=20;d=[4344 5088];
채택된 답변
Stephen23
2019년 5월 24일
편집: Stephen23
2019년 5월 24일
>> S = 'Delft_2_220_20_4344-5088.csv';
>> V = str2double(regexp(S,'\d+','match'))
V =
2 220 20 4344 5088
Using indexing to allocate those values to whatever other variables you want.
댓글 수: 2
madhan ravi
2019년 5월 24일
편집: madhan ravi
2019년 5월 24일
+1 Stephen, also if the string contains decimals then
regexp(s,'\d+[\.]?\d*','match')
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Characters and Strings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!