Hiding part of GUI until checkbox checked

10 views (last 30 days)
Hi guys I've designed a GUI using GUIDE but I'm having a few problems with openingFCN defining checkbox starting values and Callback deciding if a buttongroup is visible or not. Firstly I want the buttongroup to be invisible when the GUI starts up. Then I want checking a checkbox to control the visibility of the buttongroup. I also want the GUI to register the starting value of the checkbox, so the program knows if the checkbox was checked or not.
Firstly the part of openingFCN defining the buttongroup and checkbox and their starting values:
function trillingssterkte_menu_OpeningFcn(hObject, eventdata, handles, varargin)
% Choose default command line output for trillingssterkte_menu
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% Create Handle for radiobutton group
set(handles.SelectieCriteria,'SelectionChangeFcn',@SelectieCriteria_SelectionChangeFcn...
,'visible','off');
% Set all start values
SelectieCriteria_SelectionChangeFcn(handles.SelectieCriteria,struct('NewValue',handles.radiobutton1))
VmaxBts_Callback(handles.VmaxBts,struct('value',0))
% UIWAIT makes trillingssterkte_menu4 wait for user response (see UIRESUME)
uiwait(handles.figure1);
Secondly the Callback function of my checkbox which should make the buttongroup visible if checked and pass the value of the checkbox to the workspace if pressed.
% --- Executes on button press in VmaxBts.
function VmaxBts_Callback(hObject, eventdata, handles)
if get(handles.VmaxBts,'value') == 1
set(handles.SelectieCriteria,'visible','on')
else
set(handles.SelectieCriteria,'visible','off')
end
assignin('base','OptionVmaxBts',get(hObject,'Value'))
Unfortunatly this code gives the following error:
Error using trillingssterkte_menu4>VmaxBts_Callback (line 163)
Not enough input arguments.
Error in trillingssterkte_menu4>trillingssterkte_menu_OpeningFcn (line 72)
VmaxBts_Callback(handles.VmaxBts,struct('value',0))
Error in gui_mainfcn (line 221)
feval(gui_State.gui_OpeningFcn, gui_hFigure, [], guidata(gui_hFigure), varargin{:});
Error in trillingssterkte_menu4 (line 42)
gui_mainfcn(gui_State, varargin{:});
Line 163 being the Line where my if/else statement is written and line 72 being the line where the starting value of the checkbox is defined.
Disabling either line of code does let the GUI run, but it's unfortunately not what I want. Is there another way to set the starting value of the checkbox so it is passed to the workspace if not pressed? If I don't set a starting value the program can get buggy if run multiple times.
My thoughts at the moment are to have my main program delete this variable if it exists before the GUI is run and check then if the variable exists and set it to zero if it does not after the GUI has been exited. This way the main program will still have the variable in the workspace even if the user decides not to check the box at all. I'd prefer the GUI to do this though, any thoughts?
Matlab version is 2012b, no toolboxes.
  1 Comment
Adam
Adam on 5 Jan 2018
You shouldn't really be needing to ever call a callback manually. As its name suggests it is a callback for when the button is pressed. If you want to call the code that it runs from somewhere else as well then just create a new function that is called by both the callback and the other place and pass in the arguments you need, which will avoid the need to have a spurious 'eventData' argument which is not required.
I'm not sure why you need anything passed to the workspace either though - it is an un-necessary source of bugs.
If you have a program to run then just run it from within the GUI as that is the GUIs purpose I would assume.

Sign in to comment.

Accepted Answer

Sarah Mohamed
Sarah Mohamed on 5 Jan 2018
The error message says that on line 163, 'VmaxBts_Callback' is not being passed enough input arguments.
Line 163 appears to be:
VmaxBts_Callback(handles.VmaxBts,struct('value',0))
Here you're passing 2 input arguments. However, the definition of 'VmaxBts_Callback' expects 3:
function VmaxBts_Callback(hObject, eventdata, handles)
Looks like you need to pass the handles structure.

More Answers (0)

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!