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

New to MATLAB?

Using Button Group in MATLAB GUI

Asked by Peeyush

Peeyush (view profile)

on 31 Mar 2012

Hi,

I am trying perform this action using MATLAB GUI: i) Create a button group with 2 radio button ii)Based on user's selection, a variable (say, num) gets assigned a value ('1' for radiobutton1 and '2' for radiobutton2) iii) Output this variable with the user's selection to MATLAB workspace using OutputFcn

I am able to assign a value based on user selection to 'SolutionMethod', but I get an error in the OutputFcn: _ Error in ==> TrialGUI3>TrialGUI3_OutputFcn at 91 function varargout = TrialGUI3_OutputFcn(hObject, eventdata, handles)_

Questions:

1) How do I remove error?

2) How do I get the value of 'num' variable to MATLAB workspace?

Here's my MATLAB code:

% ---------------------------------------------------------
% Executes just before TrialGUI3 is made visible.
function TrialGUI3_OpeningFcn(hObject, eventdata, handles, varargin)
% Choose default command line output for TrialGUI3
handles.output = hObject;  
set(handles.uipanel1,'SelectionChangeFcn',@uipanel1_SelectionChangeFcn);
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes TrialGUI3 wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Executes when selected object is changed in uipanel1.
function uipanel1_SelectionChangeFcn(hObject, eventdata, handles)
switch get(eventdata.NewValue,'Tag') 
% Get Tag of selected object.
    case 'radiobutton1'
        % Code for when radiobutton1 is selected.
        num = 1;   
        disp(num);
    case 'radiobutton2'
        % Code for when radiobutton2 is selected.
        num = 2;
        disp(num);
    otherwise
        % Code for when there is no match.
end
guidata(hObject,handles);
% --- Outputs from this function are returned to the command line.
function varargout = TrialGUI3_OutputFcn(hObject, eventdata, handles) 
% varargout{1} = output.handles;
% --------------------------------------------------------------
% uipanel1: Tag for button group
% radiobutton1: Tag for radio button 1
% radiobutton2: Tag for radio button 1

Thanks in advance for your help.

0 Comments

Peeyush

Peeyush (view profile)

Products

No products are associated with this question.

0 Answers

Contact us