Transferring variables between scripts and functions
8 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (1)
Walter Roberson
el 7 de Mzo. de 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 comentarios
Ver también
Categorías
Más información sobre Entering Commands en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!