While reading data from text file line by line using fget1, If error on data how to go to next line?
Mostrar comentarios más antiguos
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
3 comentarios
Jan
el 29 de Ag. de 2013
Please follow the "? Help" link to learn how to format code.
Friedrich
el 29 de Ag. de 2013
The code you posted reads only one line from a file and can result in an endless loop. I guess you miss an additional fgetl inside the while loop. And what kind of error do you get?
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Data Import from MATLAB en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!