MATLAB: Main function of GUI with a sub function, I want to get the output of sub function as input

gui

In my gui function there is a sub function (fcn1) that I want to get its output (y) for a push button callback (fcn2) in the main function, but I cannot get the output of sub function: I appreciate if anyone can help;
function [V]=Problem
sz=get(0,'ScreenSize');
figure('numbertitle','off','menubar','none','position',[sz(3)/3 sz(4)/4 sz(3)/2.8 sz(4)/1.5]);
uicontrol('style','text','string','Select equation','position',
[20 450 180 35],'fontsize',12,'backgroundcolor','g','horizontalalignment','left');
V.al=uicontrol('style','popup','string',{'choice A','Choice B'},...
'position',[220 450 150 35],'fontsize',12,'backgroundcolor','w','horizontalalignment','left');
set(V.al,'callback',{@fcn1,V});
function [V]=fcn1(varargin)
V=varargin{3};
if get(V.al,'value')==1
helpdlg('3/x+2*x^2+1','Ref. Eqaution');
else
y=inputdlg('Vs=','User Equation',[1,33],{'sind(x)*x^2+1'});
end
end
uicontrol('style','pushbutton','string','ok','backgroundcolor','y','position',[200 20 30 30],'callback','[r]=fcn2(y);close');
end

Best Answer

function [V] = Problem
sz = get(0, 'ScreenSize');
fig = figure('numbertitle', 'off', 'menubar', 'none', 'position', [sz(3)/3 sz(4)/4 sz(3)/2.8 sz(4)/1.5], 'tag', 'Problem_fig');
uicontrol('Parent', fig, 'style', 'text', 'string', 'Select equation', 'position',
[20 450 180 35], 'fontsize', 12, 'backgroundcolor', 'g', 'horizontalalignment', 'left');
V.al = uicontrol('Parent', fig, 'style', 'popup', 'string', {'choice A','Choice B'}, ...
'position', [220 450 150 35], 'fontsize', 12, 'backgroundcolor', 'w', 'horizontalalignment', 'left', ...
'tag', 'V_a1');
set(V.al, 'callback', {@fcn1, V}, 'UserData', '');
uic3 = uicontrol('Parent', fig, 'style', 'pushbutton', 'string', 'ok', 'backgroundcolor', 'y', 'position', [200 20 30 30], 'callback', 'V_a1 = findobj(0, 'tag', ''V_a1''); y = get(V_a1, ''UserData''); [r] = fcn2(y); close(ancestor(V_a1, ''figure''))', 'enable', 'off');
function fcn1(varargin)
V = varargin{3};
if get(V.al, 'value') ==1
helpdlg('3/x+2*x^2+1','Ref. Equation');
else
y = inputdlg('Vs =', 'User Equation', [1,33], {'sind(x)*x^2+1'});
set(V.a1, 'UserData', y);
set(uic3, 'enable', 'on')
end
end
end