get numeric data from comma delimitted file
5 次查看(过去 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.
0 个评论
采纳的回答
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 Center 和 File Exchange 中查找有关 Structures 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!