I have some 50+ m files that worked in a previous driver version but are outdated for the newer driver version. As a result, I need to find and replace various variable or field names, and sometimes edit variable inputs for all these files.
For example, I’d like to find the line
src.aaaa = 100;
and replace it to:
src.bbbb = 100;
another example is to replace:
vid = videoinput('xxxx' ,1, 'yyy')
with:
vid = videoinput('kkkkkk' ,1, 'zzzz')
I’ve searched and found this discussion, that allows to search in multiple files, but not really edit or replace anything. I can handle matlab so I’m looking for a way to do that in matlab. Any ideas?
You could use the ‘Find Files’ dialog that you posted (Ctrl-Shift-F) to find each file you are looking for and then ‘Find and Replace’ (Ctrl+F) the specific lines you want to change.
As an example, find the file with
src.aaaa = 100;using Ctrl+Shift+F. Then Ctrl+F and add thesrc.aaaa = 100;to the upper textbox andsrc.bbbb = 100;to the lower textbox.From your post, it is unclear as to whether or not this would be feasible since I do not know how many different lines you would like to change in these m-files. How many are there? Are the m-files similar or are they all different?
If there are specific variables you are searching for, you could write a script to loop search through all the m-files using the
dirfunction. Read the m-file into a string variable usingfscanf. Then replace the variable in the string usingstrrep. And finally usingfprintfto write to a new .m file with the corrected variables.Refer to: