It is a very bad idea to modify a source code 400 times to modify a parameter. What about using a loop to modify the parameter inside the code? Compiling the Fortran code repeatedly is a waste of time.
But it is possible:
Str = fileread(FileName); CStr = strsplit(Str, '\n'); Match = strncmp(CStr, 'Param =', 7); CStr{Match} = sprintf('Param = %g', rand); fid = fopen(FileName, 'w'); if fid == -1 error('Cannot open file: %s', FileName); end fprintf(fid, '%s\n', CStr{:}); fclose(fid);
This changes the line starting with "Param =".