Thread Subject: switch case condition

Subject: switch case condition

From: PinkLab

Date: 24 Oct, 2009 14:57:02

Message: 1 of 4

Need help with the syntax please

function button_Callback(hObject, eventdata, handles)
switch handles
case handles.radio1(get(hObject,'Value') == get(hObject,'Max'))
% do this task

case handles.radio2(get(hObject,'Value') == get(hObject,'Max'))
% do this task

end


This above code doesn't work if i put the switch condition but if i use the if condition if goes through all the cases and doesn't check which one is selected... so please help......

Subject: switch case condition

From: PinkLab

Date: 25 Oct, 2009 14:19:01

Message: 2 of 4

Any help please?

Subject: switch case condition

From: Matt Fetterman

Date: 25 Oct, 2009 16:46:01

Message: 3 of 4

"PinkLab " <hussains_k@hotmail.com> wrote in message <hbv4ju$ol6$1@fred.mathworks.com>...
> Need help with the syntax please
>
> function button_Callback(hObject, eventdata, handles)
> switch handles
> case handles.radio1(get(hObject,'Value') == get(hObject,'Max'))
> % do this task
>
> case handles.radio2(get(hObject,'Value') == get(hObject,'Max'))
> % do this task
>
> end
>
>
> This above code doesn't work if i put the switch condition but if i use the if condition if goes through all the cases and doesn't check which one is selected... so please help......

Seems like you may not be using the switch command correctly. Can you include the code with the if condition that works? Regards! Matt

Subject: switch case condition

From: ImageAnalyst

Date: 25 Oct, 2009 17:44:44

Message: 4 of 4

On Oct 25, 10:19 am, "PinkLab " <hussain...@hotmail.com> wrote:
> Any help please?

get(hObject,'Value') == get(hObject,'Max') evaluates to either true or
false, which can be an array index but I'm not sure what you're really
after. If you're wanting to check radio button status, then I think
maybe you should try this (a bit more verbose than required just for
clarity):
radioButton1Selected = get(handles.radioButton1, 'value');
radioButton2Selected = get(handles.radioButton2, 'value');
radioButton3Selected = get(handles.radioButton3, 'value');
if radioButton1Selected
  % Do what needs to be done if radio button 1 is selected.
elseif radioButton2Selected
  % Do what needs to be done if radio button 2 is selected.
elseif radioButton3Selected
  % Do what needs to be done if radio button 3 is selected.
end

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread

Contact us at files@mathworks.com