Call variable to another function without GUI
Show older comments
I would like to ask that how can I call or use a value of variables from one function to another function or script?
Suppose I have a function named example.m in which I have four variables P,S,X and Y. I would like to use the resultant values of P and S in another function or script named FinalResult.m Keeping in mind that both P and S have range of values, lets say S=0:0.01:5; X=2; Y=6; the resultant P has range of values for different values of S.
I am not using GUI. I also would not like to use Global variable as I am writing different functions so most of the time the variable names are similar and it could cause problem.
Could someone guide me on this issue please?
Thank you
2 Comments
Note that very basic MATLAB concepts, such as how to call functions and pass data between them is covered quite well in the introductory tutorials, which are highly recommended for all beginners:
You could also simply read the MATLAB documentation, which describes all of the ways that it is possible to pass data between function workspaces:
Note that the documentation clearly states Best Practice: Passing Arguments, and this is what you should do. Using globals, assignin, or evalin make code slow and buggy, and should be avoided:
"I am writing different functions so most of the time the variable names are similar and it could cause problem"
The names that variables have inside one workspace are irrelevant to their names when allocated to input or output arguments, so it is unclear what your concern is. For example: do you know what internal variables names sin uses? Does it matter to your code how many or what internal variables sin uses? Why should it make any difference to your functions?
jack carter
on 19 Jul 2017
Accepted Answer
More Answers (0)
Categories
Find more on Historical Contests in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!