Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Hi I have a question about 'callback' function

Subject: Hi I have a question about 'callback' function

From: Minwoo

Date: 25 Jun, 2011 18:29:04

Message: 1 of 3

Hi, everyone.

I'm programming a code with GUI controller.
Now I just understand how to create GUI using uicontrol and uitext.
I would like to extract variables that I defined in sub function connected by call back function

For instance,

hw.load_session_PB = uicontrol('Style','Pushbutton',...
    'Position',[190, 350, 200, 60],'Fontname','Times New Roman',...
    'FontSize',16,'String','Load Previous Results',...
    'Visible','off');
set(hw.load_session_PB,'Callback',{@load_session_fn,hw});

function hw = load_session_fn(~,~,hw)
        hw.load_Data = 1;
end

From the above code, I would like to get 'hw.load_Data' in my workspace window.
It seems that the sub function is not able to return any defined variables.
Could you help me to get the variable in the workspace window?

Subject: Hi I have a question about 'callback' function

From: Steven_Lord

Date: 27 Jun, 2011 02:13:08

Message: 2 of 3



"Minwoo " <cmw0321@gmail.com> wrote in message
news:iu59dg$h3p$1@newscl01ah.mathworks.com...
> Hi, everyone.
>
> I'm programming a code with GUI controller.
> Now I just understand how to create GUI using uicontrol and uitext.
> I would like to extract variables that I defined in sub function connected
> by call back function
>
> For instance,
>
> hw.load_session_PB = uicontrol('Style','Pushbutton',...
> 'Position',[190, 350, 200, 60],'Fontname','Times New Roman',...
> 'FontSize',16,'String','Load Previous Results',...
> 'Visible','off');
> set(hw.load_session_PB,'Callback',{@load_session_fn,hw});
>
> function hw = load_session_fn(~,~,hw) hw.load_Data = 1;
> end
>
> From the above code, I would like to get 'hw.load_Data' in my workspace
> window.
> It seems that the sub function is not able to return any defined
> variables.
> Could you help me to get the variable in the workspace window?

In general, you shouldn't be passing variables around via the base workspace
in a GUI; only have the output from the GUI returned to the base workspace.

To pass data amongst the callbacks in your GUI, use the techniques described
in this section of the documentation:

http://www.mathworks.com/help/techdoc/creating_guis/f13-998197.html

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: Hi I have a question about 'callback' function

From: Krishna Kumar

Date: 27 Jun, 2011 09:36:04

Message: 3 of 3

"Minwoo " <cmw0321@gmail.com> wrote in message <iu59dg$h3p$1@newscl01ah.mathworks.com>...
> Hi, everyone.
>
> I'm programming a code with GUI controller.
> Now I just understand how to create GUI using uicontrol and uitext.
> I would like to extract variables that I defined in sub function connected by call back function
>
> For instance,
>
> hw.load_session_PB = uicontrol('Style','Pushbutton',...
> 'Position',[190, 350, 200, 60],'Fontname','Times New Roman',...
> 'FontSize',16,'String','Load Previous Results',...
> 'Visible','off');
> set(hw.load_session_PB,'Callback',{@load_session_fn,hw});
>
> function hw = load_session_fn(~,~,hw)
> hw.load_Data = 1;
> end
>
> From the above code, I would like to get 'hw.load_Data' in my workspace window.
> It seems that the sub function is not able to return any defined variables.
> Could you help me to get the variable in the workspace window?
Hi,
      If you want to have the variable at workspace, you can use 'assignin'. It is not clear why you need that. Also what do you mean by
> I would like to extract variables that I defined in sub function connected by call back function

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us