MATLAB: Extract a number from text file

extractfscanfnumbertext file

There are contents of a text file , which take the following form.
---------
# unique survivor object: RWL
# total count of objects: 4
# COIC lon[deg],lat[deg]: 30.831 43.061
# COIC epoch & time[UTC]: 2004/01/01 00:10:56.918
#
# __central_track__ __position_wrt_COIC__ ___P[-]/ds[km]_of_1D_swath_with_PD=fct(lat)___ _P[-]/ds[km]_of_2D_swath_with_PD=fct(lon,lat)_
# lon[deg] lat[deg] __ds[km]_ __dt[sec]_ ___P.imp__ ___Pc.min__ ___Pc.avg__
43.040 30.926 8.110 -39.030 1.200E-01 1.367E-06 1.367E-06
43.041 30.923 8.020 -38.957 1.739E-03 1.982E-08 1.982E-08
43.063 30.818 -1.060 -0.194 4.659E-01 5.308E-06 5.308E-06
I want to save as a text file by extracting only the numbers.(maintain number format) So , I do not know what you want to save by using the fscanf function. I will appreciate to tell me what I should do. Thanks in advance.

Best Answer

FID = fopen('file.txt');
form='%f %f %f %f %f %f %f'; % we have 7 columns, then use 7 %f
n = 7; % numbers of lines representing a text
out = textscan(FID, form,'headerlines', n)
fclose(FID)
cell2mat(out)