MATLAB: Extracting numbers with different decimal extention

decimalextraction

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!

Best Answer

>> S = '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';
>> C = regexp(S,'\d+,?\d*','match');
>> V = str2double(strrep(C,',','.'))
V =
35.400 50.000 57.800 57.000 54.710 58.730 61.010 61.670 60.020 57.570 57.510 61.110 64.550 67.740 68.310 66.260 60.520 60.470 62.290 43.380