Transferring variables between scripts and functions
8 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi, I have a matlab script(say test.m) which calculates a quantity(say a).Now i want to write a function(compute.m) which takes the variable a from test.m and calculate more quantities(say F). I want to call compute.m in test.m after this. Is it possible to do so?Please help. Also, how can I get two matlab scripts to share the same variable.I am aware of global variables but they work out only for functions as far as I know.Thanks!
0 Kommentare
Antworten (1)
Walter Roberson
am 7 Mär. 2013
"global" works in scripts as well. On the other hand, scripts use the current workspace instead of creating their own, so if you have one script call another, or run two scripts after each other, then they will have access to all of each other's variables.
To have the function be able to access a variable from the script that called it, you can use evalin('caller'). This is not recommended, though: it is better for the value of the variable to be passed in the call to the function.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Entering Commands finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!