Is this a switchyarding case?
Mostrar comentarios más antiguos
I have a figure with 4 checkboxes. I want to fill a 1x4 array with values of 1 if the checkbox is selected. What I've written below somewhat works, but only allows one value of chkbxvals to change and won't keep any previous values. All four checkboxes use the same callback.
So for example, if the user clicks on all four boxes, I want chkbxvals = [1 1 1 1]. If the user unchecks the first box, chkbxvals = [0 1 1 1]. If none are selected, then chkbxvals = [0 0 0 0]; and so on...
I know the long way to do this is to create 16 loops to cover all possible situations, but I feel as though there may be a more compact way to do it.
function input_chkbx_Callback(gcf,eventdata,handles,chkbxval)
chkbxvals = [0 0 0 0];
switch chkbxval
case 1
chkbxvals(1) = 1;
case 2
chkbxvals(2) = 1;
case 3
chkbxvals(3) = 1;
case 4
chkbxvals(4) = 1;
end
Thanks!
Respuesta aceptada
Más respuestas (1)
Walter Roberson
el 14 de Abr. de 2011
0 votos
What is the Callback property set to for these checkboxes? Callbacks do not take 4 inputs unless the Callback property has been set up specially, and the typical way of doing so would end up with the 4th argument always being the same as the value was when the callback property was set.
1 comentario
Iman Alsharkawi
el 14 de Abr. de 2011
Categorías
Más información sobre Entering Commands en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!