GUI Checkboxes and plot button please help
Show older comments
Hello,
I have two check boxes AB and CD and a plot button. AB and CD are array of numbers that I want to plot depending on which one is checked, and I would not like it to plot until I click the plot button. This is my code below, the problem is that it doesn't output anything and I get an error: Not enough input arguments. Please Help:
function varargout = Try1(varargin)
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @Try1_OpeningFcn, ...
'gui_OutputFcn', @Try1_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
end
function Try1_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
guidata(hObject, handles);
end
function varargout = Try1_OutputFcn(hObject, eventdata, handles)
varargout{1} = handles.output;
end
function AB_box_Callback(hObject, eventdata, handles)
AB_status=get(handles.AB_box,'value');
end
function CD_box_Callback(hObject, eventdata, handles)
CD_status=get(handles.soc_box,'value');
end
function plot_button_Callback(hObject, eventdata, handles, v_status,soc_status)
AB = [5 5.7 10.3 15.7];
CD=[45 45 22 11];
if get(AB_status,value)==1
plot(AB);
elseif get(CD_status)==1
plot(CD);
end
end
Accepted Answer
More Answers (2)
Roberto
on 27 Apr 2014
I see now... the problem... inthe 'get' function. the proper way of getting a property is:
get(handle,'Value') ;
So check this code:
function plot_button_Callback(hObject, eventdata, handles, v_status,soc_status)
AB = [5 5.7 10.3 15.7];
CD=[45 45 22 11];
if get(AB_status,'value')==1
plot(AB);
elseif get(CD_status,'value')==1
plot(CD);
end
end
function AB_box_Callback(hObject, eventdata, handles)
handles = guidata(hObject);
handles.AB_status = get(handles.AB_box,'value');
handles.CD_status = 0;
guidata(hObject, handles);
end
function CD_box_Callback(hObject, eventdata, handles)
handles = guidata(hObject);
handles.AB_status = 0;
handles.CD_status = get(handles.soc_box,'value');
guidata(hObject, handles);
end
function plot_button_Callback(hObject, eventdata, handles, v_status,soc_status)
handles = guidata(hObject);
AB = [5 5.7 10.3 15.7];
CD=[45 45 22 11];
if handles.AB_status
plot(AB);
elseif handles.CD_status
plot(CD);
end
end
You wrote "get(AB_status,value)==1", but here the get() command is not used as explained in the documentation. The first argument must be an HG-handle, but in your code a local variable should be provided.
Nevertheless, AB_status is not a local variable. It was created inside the function AB_box_Callback. But variables exist in the current workspace only and as soon as this function is left, the local variables are cleared also. Therefore you need to store it persistently and for this job guidata is applied usually.
You find a bunch of equivalent discussion when you search for "share data in gui" in this forum. Searching in the forum is recommended before asking a question.
Categories
Find more on Argument Definitions in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!