guide push button and checkbox callback

조회 수: 4 (최근 30일)
kareem
kareem 2014년 8월 1일
댓글: Adam 2014년 8월 1일
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
Adam
Adam 2014년 8월 1일
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.

댓글을 달려면 로그인하십시오.

답변 (1개)

Ben11
Ben11 2014년 8월 1일
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.

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by