I have a button group (tag: DBI_ButtonGroup) with two radio buttons (tag1: radio_DBI tag2: radio_non_DBI)
My selctionchangefcn callback is as follows:
% --- Executes when selected object is changed in DBI_ButtonGroup.
function DBI_ButtonGroup_SelectionChangeFcn(hObject, eventdata, handles)
% hObject handle to the selected object in DBI_ButtonGroup
% eventdata structure with the following fields (see UIBUTTONGROUP)
% EventName: string 'SelectionChanged' (read only)
% OldValue: handle of the previously selected object or empty if none was selected
% NewValue: handle of the currently selected object
% handles structure with handles and user data (see GUIDATA)
switch get(eventdata.NewValue,'Tag') % Get Tag of selected object.
case 'radio_DBI'
set(handles.no_ADC,'Enable','Off')
otherwise
set(handles.no_ADC,'Enable','On')
end
So I basically want to change the tag called no_ADC (which is an edit text control, to Enable = off or Enable = on based on the radio button selection. When I run this, however, MATLAB spits out the following error:
Error using handle.handle/get
Invalid or deleted object.
Error in uitools.uibuttongroup/childAddedCbk>manageButtons (line 59)
oldctrl = get(hgroup, 'OldSelectedObject');
Error while evaluating uicontrol Callback
I don't understand what is wrong.

4 Comments

I uploaded the .fig and .m file here:
http://shup.com/Shup/533222/MATLAB.zip
The only function I set up is this SelectionChangeFcn. Also, when I run the .fig, i get all kinds of warning/errors in the matlab command prompt. I don't get what is going on.
Sorry. working link:
http://www.mediafire.com/?jm3knjmoxnnw927
Is the manageButtons function a standard MATLAB function?
I am not sure what that function even does. First attempt at GUIDE.

Sign in to comment.

 Accepted Answer

Fangjun Jiang
Fangjun Jiang on 28 Sep 2011

0 votes

The code is correct. The problem seems to be caused by operator error when modifying the GUI elements. Root cause is unknown. See comments.

8 Comments

I tried that too and it didn't work either. I uploaded the files above.
Okay, I am still used to the old fashion of GUIDE programming. I think you should use switch eventdata.NewValue
Doesn't work :(
Okay, you forced me. All I can say is that I made a quick example in my new version of MATLAB. Use the same name DBI_ButtonGroup for button group, use the name radio_DBI, no_ADC too. Copy your code in the DBI_ButtonGroup_SelectionChangeFcn() and it worked. Type "dbstop if error" in Command Window and then run your GUI to see which line caused the problem. Also, you can put break point in the .m file and run the code line by line to check the value of any variables at any time.
dbstrop if error and then running my code gives me:
59 oldctrl = get(hgroup, 'OldSelectedObject');
it opens up childAddedCbk.m and points to line 59.
This is a function provided within the GUIDE package. I suspect something was screwed up when the GUI was created. Since this is just your attempt on GUIDE, why don't you re-start. Create a new blank GUIDE GUI, take a minute or two to create these two elements and try the code again. I didn't all these in less than five minutes and I found your code worked perfectly.
Hi Fangjun,
This is exactly what I just did. I basically copied/pasted the objects into a new blank GUIDE GUI and it worked. I am wondering about something though. On my first attempt, I would create objects, arrange them, etc, and save the .fig every so often. I then went back and set the TAG names for each object. Could this have been the problem? I am wondering if GUIDE breaks when you do that? On my COPY/paste attempt, I set all the tag names before saving.
Notice the function definition function DBI_ButtonGroup_SelectionChangeFcn(hObject, eventdata, handles)? The name is associated with the tag name of the GUI elements. If you change the tag name in GUIDE, the function name is supposed to be changed automatically. I mean "suppsed to". I had experience that for unknown reason, they were un-synchronized and I have to do a lot to recover it back. But I can't re-produce that procedure to prove that something is wrong with GUIDE. So, just be careful, save often and back up often.

Sign in to comment.

More Answers (1)

Alberto
Alberto on 26 Oct 2016

0 votes

I think I found the solution. Just left-click on buttongrup panel and Bring to front, also the same with all radiobuttons inside the buttongrup panel. That worked for me.

Categories

Find more on Interactive Control and Callbacks in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!