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:
How to pass value from one Button Group function to another function

Subject: How to pass value from one Button Group function to another function

From: Peng Swee Yap

Date: 1 Feb, 2010 20:50:08

Message: 1 of 9

Currently i have created two radio buttons in my GUI. I using the Button Group (SelectionChangeFcn) to control my radio button. If radio button 1 has been selected, it will pass a value "hello world 1" to another function. If radio button 2 has been selected, it will pass a value "hello world 2" to another function. Is't by using SET and GET? Can some one guide me the coding?



function hand_SelectionChangeFcn(hObject, eventdata, handles)
switch get(eventdata.NewValue,'Tag') % Get Tag of selected object.
    case 'left'
        % i need to pass 'hello world 1' to another function'
    case 'right'
        % i need to pass 'hello world 2' to another function'
    otherwise
        
end



Thank you.

Subject: How to pass value from one Button Group function to another function

From: us

Date: 1 Feb, 2010 21:03:24

Message: 2 of 9

"Peng Swee Yap" <impengswee@gmail.com> wrote in message <hk7eq0$73m$1@fred.mathworks.com>...
> Currently i have created two radio buttons in my GUI. I using the Button Group (SelectionChangeFcn) to control my radio button. If radio button 1 has been selected, it will pass a value "hello world 1" to another function. If radio button 2 has been selected, it will pass a value "hello world 2" to another function. Is't by using SET and GET? Can some one guide me the coding?
> function hand_SelectionChangeFcn(hObject, eventdata, handles)
> switch get(eventdata.NewValue,'Tag') % Get Tag of selected object.
> case 'left'
> % i need to pass 'hello world 1' to another function'
> case 'right'
> % i need to pass 'hello world 2' to another function'
> otherwise
> end

one of the many solutions
- use one of the containers, eg,

% case 'left'
     set(gcf,'userdata','hello world 1')
% ...
% then, retrieve it in the other function
     str=get(gcf,'userdata');

% also, look at
     help guidata;

us

Subject: How to pass value from one Button Group function to another function

From: Peng Swee Yap

Date: 1 Feb, 2010 21:30:27

Message: 3 of 9

"us " <us@neurol.unizh.ch> wrote in message <hk7fis$pds$1@fred.mathworks.com>...
> "Peng Swee Yap" <impengswee@gmail.com> wrote in message <hk7eq0$73m$1@fred.mathworks.com>...
> > Currently i have created two radio buttons in my GUI. I using the Button Group (SelectionChangeFcn) to control my radio button. If radio button 1 has been selected, it will pass a value "hello world 1" to another function. If radio button 2 has been selected, it will pass a value "hello world 2" to another function. Is't by using SET and GET? Can some one guide me the coding?
> > function hand_SelectionChangeFcn(hObject, eventdata, handles)
> > switch get(eventdata.NewValue,'Tag') % Get Tag of selected object.
> > case 'left'
> > % i need to pass 'hello world 1' to another function'
> > case 'right'
> > % i need to pass 'hello world 2' to another function'
> > otherwise
> > end
>
> one of the many solutions
> - use one of the containers, eg,
>
> % case 'left'
> set(gcf,'userdata','hello world 1')
> % ...
> % then, retrieve it in the other function
> str=get(gcf,'userdata');
>
> % also, look at
> help guidata;
>
> us





I have followed your example but i still fail to do it. I want to pass the value from 'handpanel' function to 'finishbutton' function. Can you help me again? My coding are as below:


function handpanel_SelectionChangeFcn(hObject, eventdata, handles)
switch get(eventdata.NewValue,'Tag') % Get Tag of selected object.
    case 'left'
        set(gcf,'UserData','left hand');
    case 'right'
        set(gcf,'UserData','right hand');
    otherwise
end


function finishbutton_Callback(hObject, eventdata, handles)
str=get(gcf,'UserData');



Thank you.

Subject: How to pass value from one Button Group function to another function

From: us

Date: 1 Feb, 2010 22:08:08

Message: 4 of 9

"Peng Swee Yap"
> function handpanel_SelectionChangeFcn(hObject, eventdata, handles)
> switch get(eventdata.NewValue,'Tag') % Get Tag of selected object.
> case 'left'
> set(gcf,'UserData','left hand');
> case 'right'
> set(gcf,'UserData','right hand');
> otherwise
> end
> function finishbutton_Callback(hObject, eventdata, handles)
> str=get(gcf,'UserData');

what is the content of STR(?)...

     disp(str); % <- put this into your 2nd callback...

us

Subject: How to pass value from one Button Group function to another function

From: Peng Swee Yap

Date: 1 Feb, 2010 22:26:06

Message: 5 of 9

"us " <us@neurol.unizh.ch> wrote in message <hk7jc8$q50$1@fred.mathworks.com>...
> "Peng Swee Yap"
> > function handpanel_SelectionChangeFcn(hObject, eventdata, handles)
> > switch get(eventdata.NewValue,'Tag') % Get Tag of selected object.
> > case 'left'
> > set(gcf,'UserData','left hand');
> > case 'right'
> > set(gcf,'UserData','right hand');
> > otherwise
> > end
> > function finishbutton_Callback(hObject, eventdata, handles)
> > str=get(gcf,'UserData');
>
> what is the content of STR(?)...
>
> disp(str); % <- put this into your 2nd callback...
>
> us



If radio button 'left' has been selected, a value of 'left hand' will pass to the 'finishbutton' function.

Subject: How to pass value from one Button Group function to another function

From: us

Date: 2 Feb, 2010 00:03:04

Message: 6 of 9

"Peng Swee Yap" <impengswee@gmail.com> wrote in message <hk7kdu$5aq$1@fred.mathworks.com>...
> "us " <us@neurol.unizh.ch> wrote in message <hk7jc8$q50$1@fred.mathworks.com>...
> > "Peng Swee Yap"
> > > function handpanel_SelectionChangeFcn(hObject, eventdata, handles)
> > > switch get(eventdata.NewValue,'Tag') % Get Tag of selected object.
> > > case 'left'
> > > set(gcf,'UserData','left hand');
> > > case 'right'
> > > set(gcf,'UserData','right hand');
> > > otherwise
> > > end
> > > function finishbutton_Callback(hObject, eventdata, handles)
> > > str=get(gcf,'UserData');
> >
> > what is the content of STR(?)...
> > disp(str); % <- put this into your 2nd callback...
> > us
> If radio button 'left' has been selected, a value of 'left hand' will pass to the 'finishbutton' function.

well, this seems to be what you need/want(?)...

us

Subject: How to pass value from one Button Group function to another function

From: Peng Swee Yap

Date: 2 Feb, 2010 05:21:02

Message: 7 of 9

"us " <us@neurol.unizh.ch> wrote in message <hk7q3o$aq6$1@fred.mathworks.com>...
> "Peng Swee Yap" <impengswee@gmail.com> wrote in message <hk7kdu$5aq$1@fred.mathworks.com>...
> > "us " <us@neurol.unizh.ch> wrote in message <hk7jc8$q50$1@fred.mathworks.com>...
> > > "Peng Swee Yap"
> > > > function handpanel_SelectionChangeFcn(hObject, eventdata, handles)
> > > > switch get(eventdata.NewValue,'Tag') % Get Tag of selected object.
> > > > case 'left'
> > > > set(gcf,'UserData','left hand');
> > > > case 'right'
> > > > set(gcf,'UserData','right hand');
> > > > otherwise
> > > > end
> > > > function finishbutton_Callback(hObject, eventdata, handles)
> > > > str=get(gcf,'UserData');
> > >
> > > what is the content of STR(?)...
> > > disp(str); % <- put this into your 2nd callback...
> > > us
> > If radio button 'left' has been selected, a value of 'left hand' will pass to the 'finishbutton' function.
>
> well, this seems to be what you need/want(?)...
>
> us


Ya, i just want to pass a simply value 'left hand' or 'right hand' to 'finishbutton' function only. But i have tried your way using 'set(gcf,'UserData','left hand');' and 'str=get(gcf,'UserData');' is not working.

Subject: How to pass value from one Button Group function to another function

From: us

Date: 2 Feb, 2010 08:02:12

Message: 8 of 9

"Peng Swee Yap" <impengswee@gmail.com> wrote in message <hk8cnu$5vf$1@fred.mathworks.com>...
> "us " <us@neurol.unizh.ch> wrote in message <hk7q3o$aq6$1@fred.mathworks.com>...
> > "Peng Swee Yap" <impengswee@gmail.com> wrote in message <hk7kdu$5aq$1@fred.mathworks.com>...
> > > "us " <us@neurol.unizh.ch> wrote in message <hk7jc8$q50$1@fred.mathworks.com>...
> > > > "Peng Swee Yap"
> > > > > function handpanel_SelectionChangeFcn(hObject, eventdata, handles)
> > > > > switch get(eventdata.NewValue,'Tag') % Get Tag of selected object.
> > > > > case 'left'
> > > > > set(gcf,'UserData','left hand');
> > > > > case 'right'
> > > > > set(gcf,'UserData','right hand');
> > > > > otherwise
> > > > > end
> > > > > function finishbutton_Callback(hObject, eventdata, handles)
> > > > > str=get(gcf,'UserData');
> > > >
> > > > what is the content of STR(?)...
> > > > disp(str); % <- put this into your 2nd callback...
> > > > us
> > > If radio button 'left' has been selected, a value of 'left hand' will pass to the 'finishbutton' function.
> >
> > well, this seems to be what you need/want(?)...
> >
> > us
>
>
> Ya, i just want to pass a simply value 'left hand' or 'right hand' to 'finishbutton' function only. But i have tried your way using 'set(gcf,'UserData','left hand');' and 'str=get(gcf,'UserData');' is not working.

WHAT is not working(?)...
in your previous post you said
...If radio button 'left' has been selected, a value of 'left hand' will pass to the 'finishbutton' function. ...
which seems just what you want...
again, what does
     disp(str);
yield(?)...
be more clear in your posts(!); do not just yell ...it does not work...

us

Subject: How to pass value from one Button Group function to another function

From: Peng Swee Yap

Date: 2 Feb, 2010 20:45:18

Message: 9 of 9

"us " <us@neurol.unizh.ch> wrote in message <hk8m64$n5a$1@fred.mathworks.com>...
> "Peng Swee Yap" <impengswee@gmail.com> wrote in message <hk8cnu$5vf$1@fred.mathworks.com>...
> > "us " <us@neurol.unizh.ch> wrote in message <hk7q3o$aq6$1@fred.mathworks.com>...
> > > "Peng Swee Yap" <impengswee@gmail.com> wrote in message <hk7kdu$5aq$1@fred.mathworks.com>...
> > > > "us " <us@neurol.unizh.ch> wrote in message <hk7jc8$q50$1@fred.mathworks.com>...
> > > > > "Peng Swee Yap"
> > > > > > function handpanel_SelectionChangeFcn(hObject, eventdata, handles)
> > > > > > switch get(eventdata.NewValue,'Tag') % Get Tag of selected object.
> > > > > > case 'left'
> > > > > > set(gcf,'UserData','left hand');
> > > > > > case 'right'
> > > > > > set(gcf,'UserData','right hand');
> > > > > > otherwise
> > > > > > end
> > > > > > function finishbutton_Callback(hObject, eventdata, handles)
> > > > > > str=get(gcf,'UserData');
> > > > >
> > > > > what is the content of STR(?)...
> > > > > disp(str); % <- put this into your 2nd callback...
> > > > > us
> > > > If radio button 'left' has been selected, a value of 'left hand' will pass to the 'finishbutton' function.
> > >
> > > well, this seems to be what you need/want(?)...
> > >
> > > us
> >
> >
> > Ya, i just want to pass a simply value 'left hand' or 'right hand' to 'finishbutton' function only. But i have tried your way using 'set(gcf,'UserData','left hand');' and 'str=get(gcf,'UserData');' is not working.
>
> WHAT is not working(?)...
> in your previous post you said
> ...If radio button 'left' has been selected, a value of 'left hand' will pass to the 'finishbutton' function. ...
> which seems just what you want...
> again, what does
> disp(str);
> yield(?)...
> be more clear in your posts(!); do not just yell ...it does not work...
>
> us


Thank you for helping me. I have solved the problem.

Tags for 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