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!