How to use a variavle calculate by a code to another code?
4 views (last 30 days)
I hope that everyone is doing well.
I have a code this code calculate the value of a variable y.
I would like to export y only to another code and I do not wana use sub function because both codes are long and I may used several same characters at different stage.
Thanks and regards
Max Heimann on 18 Jan 2022
Edited: Max Heimann on 18 Jan 2022
Im not sure i get your point about long code and reused variables. Its also a bit unclear what kind of code we are talking about.
Do you have 2 scripts script_A and script_B and want to calculate variable y in sript_A and then use it in script_B? In that case script_A will write y into the matlab base-workspace where it will be available to any code that is run after it, including script_B.
y = rand;
z = y;
Now you could type in the console:
In case we are talking about functions (which do not have direct access to the base-workspace) you could define y as a function return value.
function y = function_A
y = rand
And now you can use y in another script with
z = function_A;