So I am trying to open a bunch of .dat files(ex:frm_ais_edr_nnnn.dat', where n varys), so when I put it in a loop , fopen works for first time and when the loop runs for the second time and it takes next .dat fil fopen returns fid=-1 and it cannot be processed. the Code is as below:
clear; clc; filepath='C:\Users\K chetan\Desktop\marsis_DAta\datafiles'; out=dir(filepath); n = length(out); for count=3:n out(count,1).name fid=fopen(out(count,1).name,'r'); data_file= fread(fid,'*char'); fclose(fid); end
here the file path is the directory in which all files are present.
How can I overcome this error ?
the error its showing is
count = 4fid = -1Error using freadInvalid file identifier. Usefopen to generate a valid fileidentifier.Error in directory_test (line 8) data_file= fread(fid,'*char');
thank you
Best Answer