Hi,
I have a GUI that, by pushing a button, creates a new figure with a set of checkboxes plus a control button. The problem is that I can create the figure with all I need,however I don't know how to control the value of the checkboxes via the control button I've created. As an example, let us assume to create a single checkbox and a control button in a new figure (by pushing a button in another GUI). When I press the just created control button, I would like to set the value of the checkbot to 1. However, when I try to create a callback function for the pushbutton I always get error (seems that the handles doesn't exist).
From a previous question on the furum https://www.mathworks.com/matlabcentral/answers/13351-dialog-with-checkboxes-in-gui I have got the code to create the figure with the checkboxes and the control button, but still I cannot make the control button to control the checkboxes. I report the code in the link above:
h.f = figure('units','pixels','position',[200,200,150,50],... 'toolbar','none','menu','none');% Create yes/no checkboxes
h.c(1) = uicontrol('style','checkbox','units','pixels',... 'position',[10,30,50,15],'string','yes');h.c(2) = uicontrol('style','checkbox','units','pixels',... 'position',[90,30,50,15],'string','no'); % Create OK pushbutton
h.p = uicontrol('style','pushbutton','units','pixels',... 'position',[40,5,70,20],'string','OK',... 'callback',@p_call); % Pushbutton callback
function p_call(varargin) vals = get(h.c,'Value'); checked = find([vals{:}]); if isempty(checked) checked = 'none'; end disp(checked) end
Basically, I cannot make the callback fucntion p_call to handle the "h.c2 checkboxes…
Any help?
Thanks a lot
Best Answer