What is the best approach in editing script files with other script files ?
Show older comments
Suppose I have this in a script(A) currently:
temp1 = 435;
variable4 = 99990;
something = 56;
Using another script(B) I want this output:
new = 145;
var = 776;
thing = 9;
I have a excel spreadsheet that that has 1 column of the old variable names from A and another column that contains the new varibale name and a 3rd column with the new values. I can already change the variable names, but how do I find and replace the old values with the new values? I was thinking about using a strfind to find where the '=' and find where ';' is and then grab everything in between and replace it, but i think that this isnt the best approach for something like this. Opinions?
1 Comment
Accepted Answer
More Answers (1)
Muthu Annamalai
on 14 Aug 2015
Edited: Muthu Annamalai
on 14 Aug 2015
@Rodriguez, and @Cedric I propose an alternative way to look at the question; it would be nice to have same script return different results based on some updates.
I wonder if the updates could come from a MAT file or a CSV file, like,
function data = script_fcn()
latest_data = load('fname.mat') %or csvread(...)
data_modified = process( data ) %some processing
data = data_modified.fieldx;
end
and ofcourse the user can update the MAT/CSV from another script.
1 Comment
Cedric
on 14 Aug 2015
Ah yes, well I assumed that it was some sort of one-shot code refactoring operation. Otherwise I think that we can discourage the OP to perform this kind of operations on a regular basis.
Categories
Find more on Characters and Strings in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!