guide push button and checkbox callback

3 views (last 30 days)
kareem
kareem on 1 Aug 2014
Commented: Adam on 1 Aug 2014
i have about 40 checkboxes that each have a value, basically when i check them then click the push button, i want the push button to group them in an array (lets say x=[]) then open another m file where i can graph, i will have a plot command like ( z,x)
my checkboxes look like
"" global aa
aa=get(hObject,'Value');
if aa==1
aa=conv_data(:,3);
else
aa==0
end ""
for my push button i have
"" global xx
xx==[aa bb cc ....]
my matlab file ""
i get an error for the first checkbox so in this case aa
  1 Comment
Adam
Adam on 1 Aug 2014
I wouldn't recommend using global variables.
You can get away without using checkbox callbacks at all if you don't need anything to react to them.
Just put all your checkbox handles into an array and in the pushbutton callback call something like
checkBoxValues = get( hCheckboxes, 'Value' );
checkBoxValues = [ checkboxValues{:} ];
to give you a logical array from your checkboxes that you can then apply in whatever way you want to extract your data (I'm not sure I fully understand what your code is doing with the value of each checkbox).
Alternatively direct all your checkboxes to the same callback and use the hObject that comes through the callback to store the value for that checkbox in an array of all the checkbox values.

Sign in to comment.

Answers (1)

Ben11
Ben11 on 1 Aug 2014
Instead of using multiple if/else statements can you simply populate x directly with the values of the checkboxes:
x = [get(handles.checkbox1,'Value') get(handles.checkbox2,'Value') get(handles.checkbox3,'Value')... get(handles.checkbox40,'Value')];
then you have your 1x40 vector containing either 0 or 1 for each particular checkbox.

Categories

Find more on Migrate GUIDE Apps 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!