I am trying to write a robust read command for my application. I want the read code to be able to handle whether the *.txt has a header (title) line or not.
The user will create a trajectory file that is always 7 columns wide and an unknown length. The first line can either be a title line for the columns or not. Typically I create my files in excel and then save them using the "Unicode Text" format. I know I could use xlsread() but I would prefer to read from a text file for versatility. Here's my current code:
In_fID=fopen([Dir,File],'r');
FirstLine=fgetl(In_fID);
model_data=textscan(In_fID,'%f %f %f %f %f %f %f');
if ischar(FirstLine)
model_data=cell2mat(model_data);
else
FirstLine=cell2mat(FirstLine);
model_data=cel2mat(model_data);
model_data=[FirstLine;model_data];
end
Regardless of whether the first line is a header line like "Time x y z r p yw" or the first coordinate of my trajectory (For example: "0 0 0 0 0 0 0") ischar(Firstline)
always returns true (1). Does anyone know how I can fix this?