I have written a matlab code to read and average certain data in number of files in a folder and write the averaged value back as a file in the same folder. But I am getting some issues in the code.
n_in = 2;
n_out = 15362;
N_input = 7;
N_time = 20;
fname = sprintf('vel_xz00%01.f0000',j);
fdata = fopen(fname);
topline = fgetl(fdata);
N_tot = (n_out - n_in)*N_input;
Data_tmp = fscanf(fdata,'%f',N_tot);
Time(j).Data_sim(:,i) = Data_tmp(i:7:N_tot);
My files in the folder have the filename as vel_xz0010000 till vel_xz0200000. The code can read the values of the datas from files vel_xz0010000 till vel_xz0090000 but after that cannot read the values from vel_xz0100000 til vel_xz0200000. It gives the following error:
Error using fgets Invalid file identifier. Use fopen to generate a valid file identifier.
Error in fgetl (line 33) [tline,lt] = fgets(fid);
Error in Flow_field_postprocessing (line 16) topline = fgetl(fdata);
Also these files have datas in 15360 X 7 matrix. I want to get the average values of (1,1)element to (15360,7)element of all the files from vel_xz0010000 to vel_xz0200000 and store them as a new vel_xz file with 15360 X 7 elements. Like average of all the (1,1) elements of the 20 files, average of all the (1,2) elements of the 20 files and like so on.