How do I make variables that I enter in a script to apply to a second script without need to run or open the second one?
3 views (last 30 days)
I would like to enter variables in a VARIABLE_script.m
and once I run this variable_script.m it should
a) write the values in a MAIN_script.m
b) run the MAIN_script.m automatically.
The key intention is to avoid opening the MAIN_script.m
and by entering many variables makes fatal changes in
The idea with a VARIABLE_script.m should fix this problem.
Below I give a small example to illustrate the problem:
Let the MAIN_SCRIPT.m contain the following commands:
In the VARIABLE_script.m I would like to enter ONLY the values of
k, l, m and alpha.
Then I need to write some command lines (THIS IS THE QUESTION!!!)
indicating in which script the variable should be written and
and by running VARIABLE_script.m
the Main_script would automatically adsorb the values,
execute the functions and give the output the output (for this very
I hope someone can help me with this issue.
Thanks a lot for your attention
Walter Roberson on 15 Apr 2011
Also, in your main script, as long as it remains a script (and not a function), you could code
if ~exist('alpha','variable'); alpha=2; end
and so on for the other variables. Then any variable that already has a value will not have that value overwritten by the main script.
More Answers (1)
Friedrich on 15 Apr 2011
I think the easiest way is to use a function, because they are designed to do this.
function [n, o, p, N, M] = my_func(k,l,m,alpha)
And you call it through
[a b c d e] = my_func(1,1,15,2)