MATLAB: Transfer variables between functions

MATLAB and Simulink Student Suitematlab function

I am trying to use a function to develop my variables for the rest of my code since its used multiple times. here is an example. try to keep it simple since I just recently started learning MATLAB. basically want De and RE to be used in the function below.
function single_data (~,~)
p = input('density/kg/m^3 ');
e = input('surface roughness/m ');
D = input('diameter/m ');
Q = input('volumetric flowrate/m^3/s ');
u = input('viscosity/pa/s ');
A = input('cross-sectional aream/m^2 ');
De = e/D;
syms s
eqn = (p*D*Q)/(u*A) == s;
RE = vpasolve(eqn,s);
f3 = figure(3);
FA = uicontrol(f3,'Style','togglebutton','callback', @frictionFA,'String','automated(vpasolve) ','Position',[20 20 200 30]);
FBS = uicontrol(f3,'Style','togglebutton','callback', @frictionFBS,'String','bisection method','Position',[20 50 200 30]);
FNR = uicontrol(f3,'Style','togglebutton','callback', @frictionFNR,'String','Newton Rhapson Method ','Position',[20 80 200 30]);
end
function frictionFA (~,~)
syms fA
eqntwo = 1/sqrt(fA) == -2*log((De)/(3.7)+(2.51)/(RE*sqrt(fA)));
AS = vpasolve(eqntwo,fA);
fprint(AS)
end

Best Answer

Variables cannot be "transfered" between functions. You need to provide them as inputs and outputs.
Combining GUI and the actual code makes it much harder to maintain the code. You have to struggle with callbacks and sharing data at the same time, so this is a bad design. But it works:
Store the data to be shared in a struct and provide them as inputs to the callback:
data.eqn = (p*D*Q)/(u*A) == s;
data.RE = vpasolve(eqn,s);
FA = uicontrol(f3,'Style','togglebutton','callback', {@frictionFA, data}, ...
function frictionFA (~,~, data)
disp(data.RE) % Just as demonstration
...
end