Azzera filtri
Azzera filtri

get numeric data from comma delimitted file

2 visualizzazioni (ultimi 30 giorni)
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.

Risposta accettata

Walter Roberson
Walter Roberson il 7 Giu 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?

Più risposte (0)

Categorie

Scopri di più su Denoising and Compression in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by