MATLAB: Remove letters tabs and spaces from a string with numbers and letters while creating a vector with the remaining numbers

string manipulationstring parsing

Hello,
I have a file called "SSL.dat". The second line has some numbers I need but it's full of spaces and letters.
fidssl = fopen('SSL.txt','r');
line1ssl=fgetl(fidssl);
line2ssl=fgetl(fidssl); %line where the data I need is
This line has the following contents:
mass(Msun) 1.000 9.547922048e-4 2.858857575e-4 4.366245355e-5 5.151391279e-5 8.3459e-9 3.040433607e-6 1.660477111e-7 2.448326284e-6 3.227778035e-7 6.607313077e-9
There are spaces, not tabs, separating each column. I need to remove the letters and split each mass value into a vector so that the vector index matches the column number of said value.
For example, the value "1.000" would match mass(1) and so on.
Can anyone help?

Best Answer

I got a solution. When I use textscan() it keeps everything store as strings. All I have to to is convert them to doubles like so,
fidssl = fopen('SSL.dat','r');
line1_ssl=fgetl(fidssl);
planet_name_list = textscan(line1_ssl,'%s');
line2_ssl=fgetl(fidssl);
masslist = textscan(line2_ssl,'%s');
for i=1:12
mass(i)=str2double(masslist{1}{i+2})
end
seems to work
Related Question