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5, %5.5, %5.5f\n',n_new_1,n_new_2,n_new_3,n_new_4);
fclose(fid);
Error in ==> n_iterations at 22
fprintf(fid,'%5.5, %5.5, %5.5,
Error in ==> run at 74
evalin('caller',[script ';']);