Index exceeds matrix dimentions erro in matlab -


this part of script:

fid = fopen([directory '001/listing.txt'],'r'); tline = fgetl(fid);  ii = 0; while (tline ~= -1)     ii = ii + 1;     year(ii) = str2num(tline(11:14));     month(ii) = str2num(tline(15:16));     day(ii) = str2num(tline(17:18));     hour(ii) = str2num(tline(20:21));     min(ii) = str2num(tline(22:23));     sec(ii) = str2num(tline(24:25));     tline = fgetl(fid); end  fclose(fid); 

i keep getting error "index exceeds matrix dimensions". can me here?

sometimes tline less 25 characters long.

my guess have blank lines in file doesn't cause fgetl return -1 empty string instead.

put if after while skip empty lines:

if (length(tline) == 0)       continue end 

if still have problems, change == 0 part <25 make sure lines process @ least 25 characters long.


Comments