Getting the default radio button value from a button group

Hello!
I'm making a gui with multiple button groups that define values which is to be used in a function triggered by a push button.
My problem is that when I want the default radio button in the button group, I must "activate" it by pressing another button first, and then choosing it, else the value ends up empty.
Simplification of the code:
function indata2_OpeningFcn(hObject, ~, handles, varargin)
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
function RUNpush_Callback(~, eventdata, handles)
St=get(handles.shiptype,'UserData');
%Send values into function
FunctionoutsideGUI(St)
%One of the button groups:
function shiptype_SelectionChangeFcn(hObject, eventdata, handles)
handles = guidata(hObject);
switch get(eventdata.NewValue,'Tag') % Get Tag of selected object.
case 'St1'
st=1;
case 'St2'
st=2;
end
set(handles.shiptype,'UserData',st);
guidata(hObject,handles)
Hope someone can help me, Im realy struggeling with this, and I want to get it rigth.
-Lina

Respuestas (1)

Matt Fig
Matt Fig el 14 de Ag. de 2012
GUI_8 demonstrates this.

1 comentario

Lina
Lina el 15 de Ag. de 2012
Editada: Lina el 15 de Ag. de 2012
Thank you for your reply, but by adapting my code to the one in GUI_8, matlab stoped recognicing my st values inside the switch. I tried moving
set(handles.shiptype,'UserData',st);
Into the case code, and swaping st for the value, but St in the push button ended up blank.
I tried adding a handel.st=0 in the opening function, and adapting the same swich code as in the example, but handles.st remains 0 even though I activale the radiobutton.
This is how i my code looks now:
function indata2_OpeningFcn(hObject, ~, handles, varargin)
set(handles.shiptype,'SelectionChangeFcn',@shiptype_SelectionChangeFcn);
set(handles.shiptype,'SelectedObject',[]); % No selection
set(handles.shiptype,'Visible','on');
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
function RUNpush_Callback(~, eventdata, handles)
St=get(handles.shiptype,'UserData');
%Send values into function
FunctionoutsideGUI(St)%One of the button groups:
function shiptype_SelectionChangeFcn(hObject, eventdata, handles)
handles = guidata(hObject);
switch findobj(get(hObject,'selectedobject'))
case 'St1'
set(handles.shiptype,'UserData',1);
case 'St2'
set(handles.shiptype,'UserData',2);
end
guidata(hObject,handles)
Any ideas?

Iniciar sesión para comentar.

Categorías

Más información sobre Interactive Control and Callbacks en Centro de ayuda y File Exchange.

Preguntada:

el 14 de Ag. de 2012

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by