MATLAB: I have a .DAT file when i am loading the file then only first set of data is being getting processed.

.dat fileMATLAB

i tried to load the data from the .dat format of file. i have data for t=1,3…,30. but i cannot process it for rest of t values apart from t=1. i cannot share file here as it is too heavy to upload here.

Best Answer

filename = 'C2_PLA_3h.dat';
headerlinesIn = 3;
fmt = repmat('%f', 1, 6);
[frit, msg] = fopen(filename, 'r');
if frit < 0
error('cannot open file "%s" because "%s"', filename, msg);
end
timestep = 0;
datasections = {};
while ~feof(frit)
this_section = textscan(frit, fmt, 'headerlines', headerlinesIn, 'CollectOutput', true);
if isempty(this_section) || isempty(this_section{1}) %end of file
break
end
timestep = timestep + 1;
datasections{timestep} = this_section{1};
end
fclose(frit);