MATLAB: Call variable to another function without GUI

functionvariable

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

Best Answer

" 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"
So define those variables as output arguments, just like the function help shows:
function [P,S] = example(...)
...
P = ...
S = ...
end
"use the resultant values of P and S in another function or script named FinalResult.m"
and then you can simply get those values when you call example from within FinalResult:
[Pout,Sout] = example();
"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"
This seems to be unrelated to the task of passing values between workspaces, and it is unclear to me what relevance that has to your quetion.