What is the best approach in editing script files with other script files ?
이전 댓글 표시
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
채택된 답변
추가 답변 (1개)
Muthu Annamalai
2015년 8월 14일
편집: Muthu Annamalai
2015년 8월 14일
@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
Cedric
2015년 8월 14일
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.
카테고리
도움말 센터 및 File Exchange에서 Characters and Strings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!