Filter löschen
Filter löschen

MATLAB : access to the callback function of checkbox

4 Ansichten (letzte 30 Tage)
Sarah Guiffray
Sarah Guiffray am 19 Mär. 2015
Bearbeitet: Adam am 19 Mär. 2015
Hello, I have some checkbox and a push button to select all of them.
Code of my button "Select all" :
for i = 1:5
set(sprintf('handles.check%d',i),'value', 1)
end
But, I would like to go to the checkbox callback function each time I select one of them. How can I do this ? Because for the moment, all my check box are selected when I push the button "Select all" but the code into each checkbxo is not executed. My code in a checkbox is :
function check1_Callback(hObject, eventdata, handles)
if(get(hObject ,'Value') == 1)
ind=1;
assignin('base','ind',ind);
end
end

Akzeptierte Antwort

Adam
Adam am 19 Mär. 2015
Bearbeitet: Adam am 19 Mär. 2015
Factor out your checkbox callbacks to something like this:
function checkBoxCallback( hCheckbox, ind )
if ( logical( get( hCheckbox, 'Value' ) )
assignin('base','ind',ind);
end
then an individual callback would just be e.g.
function check1_Callback(hObject, eventdata, handles)
checkBoxCallback( hObject, 1 );
and in the for loop you put at the top of your question just add in a call to this new factored out function as e.g.
for i = 1:5
set(sprintf('handles.check%d',i),'value', 1)
checkBoxCallback( handles.( sprintf( 'check%d', i ) ), i );
end
I may have made a few syntax errors there as I am typing straight into here without testing in Matlab first, but hopefully you get the idea even if the syntax is not exact.

Weitere Antworten (0)

Kategorien

Mehr zu Interactive Control and Callbacks finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by