function modify_INP(infile, outfile, new_E) % Open input file fid_in = fopen(infile, 'r'); if fid_in == -1 error('Could not open input file.'); end % Open output file fid_out = fopen(outfile, 'w'); if fid_out == -1 fclose(fid_in); error('Could not create output file.'); end % Read input file line by line while ~feof(fid_in) line = fgetl(fid_in); % Check for material definition lines and modify E1 and E2 and E3 if contains(char(line), '0.1, 0.49') && ~isnan(new_E) fprintf(fid_out, '%f, 0.49\n',new_E); else fprintf(fid_out, '%s\n', line); end end