get numeric data from comma delimitted file

2 views (last 30 days)
Hello i am reading a file and when i find some specific characters i want to get from that line some numbers. My problem is that the format of the line isn't fixed so i can't use sscanf to read. To be more specific
if findstr(tline,'#FLIGHT_SUMMARY')==1
tline=fgetl(fid);
totalo3=sscanf(tline,'%g,%g,%g,%g,%g,%*s');
this works fine when for example tline is as follows
tline='342.87,3,366.25,-1.031,377.60,,,TOMS'
but i can't use it when the fomat of tline is
tline='231.1,0,,,353.0,0,0,Brewer,019'
because of the "empty" comma values. In any case i am interesting just to keep the first 5 comma separated values, so as to use some of them somewhere later on my code. I would appreciate any help.

Accepted Answer

Walter Roberson
Walter Roberson on 7 Jun 2012
totalo3Cell = textscan(tline,'%f%f%f%f%f', 'Delimiter', ',', 'CollectOutput', 1);
totalo3 = total3Cell{1};
This should substitute NaN for the missing values.
... Or did you want the first 5 values that are present?

More Answers (0)

Categories

Find more on Denoising and Compression in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!