This is probably a little too specific to your case, i.e. it's looking for a particular text. I'm just using strrep but if it doesn't work, you may have to look at regexprep. In general, I agree with Rick that you should do this from the beginning (using your original file), instead of creating 1000 copies, changing the file names, and then changing those 2 lines.
d = dir('*.a_process');
for id = 1:length(d)
[p, name] = fileparts(d(id).name);
fid = fopen(d(id).name, 'r');
str = textscan(fid, '%s', 'delimiter', '\n', 'whitespace', '');
fclose(fid);
newStr = strrep(str{1}, 'Run RW Cycle', ['Run ', name, ' Cycle']);
newStr = strrep(newStr, 'RW.mat', [name, '.mat']);
fid = fopen(d(id).name, 'w');
fprintf(fid, '%s\n', newStr{:});
fclose(fid);
end
Best Answer