Reputation: 21
I tried many things and looked with thousant of keywords thru google and stackoverflow and I literally always fall on the very same (useless for me) solutions.
Here's my problem:
I have a GUI with a uibuttongroup "Youpi" with two radio buttons "visible" and "invi". I have an other uipanel "Tralala" .
I create the following code:
function Youpi_SelectionChangeFcn(hObject,eventdata)
switch get(eventdata.NewValue,'Tag') % Get Tag of selected object.
case 'visible'
set(handles.Tralala, 'visible', 'on');
case 'invi'
set(handles.Tralala, 'visible', 'off');
otherwise
% Code for when there is no match.
end
It does not work and I get always the same error message (see below).
I made these two tests to figure out where the problem is from:
_I changed the case by a disp function : when I toggle my two radio buttons, the messages are displayed properly. It does not come from SelectionChangeFcn function.
_In the very first function, called "GUI_OpeningFcn" , I input set(handles.Tralala, 'visible', 'off');
and it works properly (e.g. I don't see the panel if I run the GUI).
Do you know why the panel handle disappears from one function to an other ?
Here's the error message :
??? Undefined variable "Tralala" or class "handles.Tralala".
Error in ==> MaccorGUI>Youpi_SelectionChangeFcn at 272
set(handles.Tralala, 'visible', 'on');
Error in ==> hgfeval at 63
feval(fcn{1},varargin{:},fcn{2:end});
Error in ==> uitools.uibuttongroup.childAddedCbk>manageButtons at 80
hgfeval(cbk, source, evdata);
??? Error while evaluating uicontrol Callback
Please help me find a solution.
Thank you.
Upvotes: 0
Views: 6044
Reputation: 1
I created a group panel with a button each time I was one of the button selects an image he m'aficher each button has an image thank you for helping me to find the source code I'm doing it uipanel4_SelectionChangeFcn function (hObject, EVENTDATA, handles) % hObject handle To The selected object in uipanel4 % With The followings EVENTDATA structure fields (see UIBUTTONGROUP) % EventName: string 'SelectionChanged' (read only) % OldValue: handle Of The Previously selected object or empty if none selected WAS % NewValue: handle Of The Currently selected object % handles structure with handle and user data (see GUIDAT) if RadioButton1 == get (handles.radiobutton1, 'value', 1) Set (handles.axes4, 'because') else radioButton2 == get (handles.radiobutton2, 'value', 1) Set (handles.axes4 'man')
Upvotes: 0
Reputation: 21
Ok I found the solution. I don't think it is the best one but at least it works.
Before "switch" i added the following command:
a = guidata(get(hObject,'parent'));
And in the switch instead of using "handles" I use "a".
note: it works also with guihandles ( you can have access to handles.output this way)
Upvotes: 2
Reputation: 8290
You need to add handles to the selection change function definition
function Youpi_SelectionChangeFcn(hObject,eventdata, handles)
Upvotes: 0