While reading data from text file line by line using fget1, If error on data how to go to next line?
Show older comments
Hi, I am new to this form so sorry for any mistakes.
My question is what I am after. So I have set of data been read line by line using fget1, but my data can have sometimes lines or some data missing.
So what I need program to do is if there is empty line but not EOf, or if data missing within each line just fill with NaN or skip and go to next line.
example of my code:
try
tline = fgetl(fileID);
while (tline ~= -1)
if (strncmp(tline,'01',2))
%get data
Time_num=addtodate(Time_num,100,'millisecond');
Data = textscan(tline,'%*s%*s%*s%d16%d16%d16%d16%d16%d16%c%c%c%c%c%c\n'...
,'delimiter',',');
DATA(dataLine,:) = cell2mat(Data(1,1:6));
%V_A(dataLine,:)=Data(1,7:12);
Time_Axis(dataLine,:)=Time_num;
dataLine=dataLine+1;
end
end
catch err
errordlg('There has been an error with your Import File.',' File Error #2017');
end
Accepted Answer
More Answers (0)
Categories
Find more on Data Import from MATLAB in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!