Saving file name in a variable worked for me. Try running the following code:
for i = 1:30
name=string(i)+'.asc';
fid = fopen(name, 'r');
C = textscan(fid, '%s%s', 'Delimiter',',', 'HeaderLines', 1);
for k = 1:1046
E(k,1) = E(k,1) + str2double(string(C{1,1}(k,1)));
E(k,2) = E(k,2) + str2double(string(C{1,2}(k,1)));
end
fclose(fid);
end
E = (1/30) * E;
E
I guess creating the name of file in fopen is causing the problem.