get numeric data from comma delimitted file

2 次查看(过去 30 天)
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.

采纳的回答

Walter Roberson
Walter Roberson 2012-6-7
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?

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Denoising and Compression 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by