From: Moses on
I've read through a lot of posts regarding setting the values of the radio button (and really any buttons) and coded accordingly but get an error when trying to do so and was wondering if anyone could point out what was wrong.

I have 4 radio buttons and when one is selected, I want to disable the others

this is one of the callback's

function 1_radiobutton_Callback(hObject, eventdata, handles)

if (get(handles.1_radiobutton, 'Value') == get(hObject, 'Max'))
for temp = 1:4
if temp == 1
else
set(eval([num2str(temp) '_radiobutton']), 'Value', 0);
end
end
end

however, when i test it out by turning on one of the other radio buttons I get the error:
??? Error using ==> set
Invalid handle object.
From: Walter Roberson on
Moses wrote:
> I've read through a lot of posts regarding setting the values of the
> radio button (and really any buttons) and coded accordingly but get an
> error when trying to do so and was wondering if anyone could point out
> what was wrong.

> I have 4 radio buttons and when one is selected, I want to disable the
> others

Perhaps you should be using a button group?

> this is one of the callback's
>
> function 1_radiobutton_Callback(hObject, eventdata, handles)

Naming functions with a leading number is not permitted: the first
character of any identifier must be an alphabetic character.


> if (get(handles.1_radiobutton, 'Value') == get(hObject, 'Max'))
> for temp = 1:4
> if temp == 1
> else
> set(eval([num2str(temp) '_radiobutton']), 'Value', 0);
> end
> end
> end
>
> however, when i test it out by turning on one of the other radio buttons
> I get the error:
> ??? Error using ==> set
> Invalid handle object.

You have not defined that handle within the function itself. Is this a
nested function? If not then what scope are you expecting the variables
to be found in? I notice that you refer to handles.1_radiobutton in your
get(), but you have a "bare" 2_radiobutton the first time you set: did
you perhaps want handles.2_radiobutton there? (If that was a valid
identifier, that is?) If so, then you do not need eval:

set(handles.(sprintf('radiobutton%d',temp)), 'Value', 0)

Button groups automatically do this management for you.
 | 
Pages: 1
Prev: row operation
Next: mmreader codec problems