Hi everybody, I still have the same problem!
I changed the code a little, see below, and it worked good for a few optimization problems but now again I get an error when Matlab is trying to write to a file. The code is as follows:
[fid msg]=fopen('track.dat','w');
fprintf(fid,'Sys\n');
fprintf(fid,'==================================================================\n');
fprintf(fid,'met\n\n');
fprintf(fid,'%10s\t%10s\t%10s\t%10s\t%10s\t%10s\n','x','y','h','V','T','m');
fprintf(fid,'==================================================================\n');
fprintf(fid,'%10.3f\t%10.3f\t%10.3f\t%10.3f\t%10.3f\t%10.0f\n',INM_data');
fprintf(fid,'\n==================================================================\n');
fprintf(fid,'%6s\r\n',c.ET);
fprintf(fid,'%6s\r\n',c.EM);
fclose(fid);
x_min=round((min(x_arr)-8000)/100)*100;
x_max=round((max(x_arr)+8000)/100)*100;
y_min=round((min(y_arr)-8000)/100)*100;
y_max=round((max(y_arr)+8000)/100)*100;
[fid2 msg]=fopen('grid2D.dat','w');
fprintf(fid2,'%10s\t%10s\t%10s\t%10s\t%10s\t%10s\r\n','x_min','x_max','x_sz','y_min','y_max','y_sz');
fprintf(fid2,'==================================================================\n');
fprintf(fid2,'%10f\t%10f\t%10f\t%10f\t%10f\t%10f\r\n',x_min,x_max,500,y_min,y_max,500);
fclose(fid2);
status=system('INMmodel.exe track.dat grid2D.dat' );
delete('track.dat','grid2D.dat');
As can be seen I open the files, I write something, close them and then even delete them.
I run the optimization problems for 200 generations and with a population of 50. The error occurs random, or at least I don't see any pattern in it. The message I get:
fid = -1
msg= Permission denied
And then with the next line I get an error in fprintf saying:
Invalid file identifier. Use fopen to generate a valid file identifier.
Does anybody have any idea why this is happening?