Transferring variables between scripts and functions
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposte (1)
Walter Roberson
il 7 Mar 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 Commenti
Vedere anche
Categorie
Scopri di più su Entering Commands in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!