extracting numbers with different decimal extention
이전 댓글 표시
Hi! I have a line in my file:
OutputY: 35,40 50 57,80 57 54,71 58,73 61,01 61,67 60,02 57,57 57,51 61,11 64,55 67,74 68,31 66,26 60,52 60,47 62,29 43,38
There some numbers have 2 decimal places and some numbers don't have it at all. When I use:
A1 = regexp(TRGT_a,'[\d*\.]*\d*','match') %TRGT_a is my variable with many columns like OutputY
it sees every number separately and instead of 20 values with decimal extension, I have 38 values... I would appreciate if you could help me to solve this? Also I will have to change all comas to fulstops to do further calculations.
Thank you in advance!
채택된 답변
추가 답변 (1개)
dpb
2018년 10월 24일
I'm sure there is regexp but I'm just not adept-enough w/o a lot of time and effort...the "dead-ahead" solution--
>> fmt=['Output Y:' repmat('%f',1,sum(s==9))];
>> dat=cell2mat(textscan(strrep(s,',','.'),fmt))
dat =
Columns 1 through 17
35.4000 50.0000 57.8000 57.0000 54.7100 58.7300 61.0100 61.6700 60.0200 57.5700 57.5100 61.1100 64.5500 67.7400 68.3100 66.2600 60.5200
Columns 18 through 20
60.4700 62.2900 43.3800
>>
카테고리
도움말 센터 및 File Exchange에서 Characters and Strings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
