Thread Subject: Button Callback - Matlab Issue

Subject: Button Callback - Matlab Issue

From: PinkLab

Date: 22 Oct, 2009 14:35:13

Message: 1 of 7

I am trying to create a callback on push button,

If radio1 is selected then run case 1
If radio2 is selected then run case 2
If radio3 is selected then run case 3

Any hint how to write this code??

Subject: Button Callback - Matlab Issue

From: Lars

Date: 22 Oct, 2009 14:53:03

Message: 2 of 7

"PinkLab " <hussains_k@hotmail.com> wrote in message <hbpqj1$i7o$1@fred.mathworks.com>...
> I am trying to create a callback on push button,
>
> If radio1 is selected then run case 1
> If radio2 is selected then run case 2
> If radio3 is selected then run case 3
>
> Any hint how to write this code??

get( radio1, value)

see also button group

Subject: Button Callback - Matlab Issue

From: Dave Robinson

Date: 22 Oct, 2009 15:22:22

Message: 3 of 7

"PinkLab " <hussains_k@hotmail.com> wrote in message <hbpqj1$i7o$1@fred.mathworks.com>...
> I am trying to create a callback on push button,
>
> If radio1 is selected then run case 1
> If radio2 is selected then run case 2
> If radio3 is selected then run case 3
>
> Any hint how to write this code??

Straight off of the top of my head (meaning there is probably a lot slicker ways of doing it)

1) Define yourself a handles variable say handles.Case_Select

2) In your radio1 button callback insert something like
handles.CaseSelect = 1;
% Update handles structure
guidata(hObject, handles);

3) In your radio2 button callback
handles.CaseSelect = 2;
% Update handles structure
guidata(hObject, handles);

etc.

Now your switch statement looks like
switch handles.CaseSelect
   case(1)
      --- do case1 things---
  case(2)
     ---do case2 things


end

Its rather crude, but should do what you want. If I think of a better idea, I will come back.

Regards

Dave Robinson

Subject: Button Callback - Matlab Issue

From: Matt Fig

Date: 22 Oct, 2009 16:08:21

Message: 4 of 7

Have all three call the same callback:

function []=radio_callback(hObject,EventData,handles)

switch hObject
    case handles.radio1
        % run case 1
    case handles.radio2
        % run case 2
    case handles.radio3
        % run case 3
    otherwise
        % Whatever
end

Subject: Button Callback - Matlab Issue

From: Lars

Date: 22 Oct, 2009 17:22:19

Message: 5 of 7

If I understood right you want to implement a callback of a pushbutton.
That can mean the action occurs not by selecting a radio button?

In this case a variable like "handles.myCaseId" is a good solution.

If action shall occure by clicking a radio button AND they are exclusive, meaning activating one radio will deactivate the other(s), then a buttonGroupBox is the solution. In this case you can implement the selectionChanged-function of the buttonGroupBox.

Subject: Button Callback - Matlab Issue

From: PinkLab

Date: 23 Oct, 2009 09:57:06

Message: 6 of 7

Yes, you are right, i need callback in Button1 so when radio1 is selected do that task otherwise depending on which radio is selected do that particular task.... the task is to create a plot on axes so please help.........




"Lars" <mustermann.klaus.TO.REMOVE@gmx.de> wrote in message <hbq4cb$ecq$1@fred.mathworks.com>...
> If I understood right you want to implement a callback of a pushbutton.
> That can mean the action occurs not by selecting a radio button?
>
> In this case a variable like "handles.myCaseId" is a good solution.
>
> If action shall occure by clicking a radio button AND they are exclusive, meaning activating one radio will deactivate the other(s), then a buttonGroupBox is the solution. In this case you can implement the selectionChanged-function of the buttonGroupBox.

Subject: Button Callback - Matlab Issue

From: PinkLab

Date: 23 Oct, 2009 14:29:19

Message: 7 of 7

Matt, it didn't work... i am not sure why it is not plotting the graph on my axes in GUI after i press the generate button...



"Matt Fig" <spamanon@yahoo.com> wrote in message <hbq01l$of$1@fred.mathworks.com>...
> Have all three call the same callback:
>
> function []=radio_callback(hObject,EventData,handles)
>
> switch hObject
> case handles.radio1
> % run case 1
> case handles.radio2
> % run case 2
> case handles.radio3
> % run case 3
> otherwise
> % Whatever
> end

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

rssFeed for this Thread

Contact us at files@mathworks.com