Question about two Checkboxes being checked and increment a number

1 view (last 30 days)
Hello friends. I am generating an output number based on a certain criteria. When I click on one checkbox, I display the value as 1, and when I click on the second checkbox, the value is 1 as well. However, when both checkboxes are clicked, the value should be 2. I am unable to output 2 in my pushbutton even after declaring a variable. If anyone can help, it will be great. Thank you so much :) Here is my code below:
ml = get(handles.checkbox_trial,'Value');
ml1 = get(handles.checkbox1,'Value');
ml2 = get(handles.checkbox2,'Value');
if ml == 1
handles.Level = '0'
elseif ml1 == 1
handles.Level = '1'
elseif ml2 == 1
handles.Level = '1'
elseif ...
msgbox([handles.Level]);
The last elseif condition can be edited. I was thinking of adding by using a level number like handles.Level = 0; and then incrementing the number, but it is not working

Accepted Answer

Adam Danz
Adam Danz on 2 Oct 2019
Edited: Adam Danz on 2 Oct 2019
ml = get(handles.checkbox_trial,'Value');
ml1 = get(handles.checkbox1,'Value');
ml2 = get(handles.checkbox2,'Value');
if ml == 1
handles.Level = '0'
else
handles.Level = num2str(ml1 + ml2);
end
msgbox([handles.Level]);
  1 Comment
Adam Danz
Adam Danz on 2 Oct 2019
I'm lost at:
"Only for the first radiobutton my ouput should be 0(Not Observed), 0.5(Observed) and 1(Observed). For the rest of radiobuttons my output should be 0, 0.25 and 0.5."
Radiobuttons do not have outputs. Their value is binary (0/1). You can assign weights to those values such as handles.radioButton1.Value * 0.5.
Is that what you're doing?

Sign in to comment.

More Answers (0)

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!