Error gui_mainfcn(gui_State, varargin{:});
Show older comments
I need to make a program that will build the given functions, and for this I created a GUI through GUIDE, but when I write the function, it gives an error
Error gui_mainfcn(gui_State, varargin{:}); Error in matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)TOSAPRLAB4('pushbutton1_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback.
and I can't figure out what exactly is the problem. Am I doing something wrong or is the code outdated?
here is my code:
function varargout = TOSAPRLAB4(varargin)
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @TOSAPRLAB4_OpeningFcn, ...
'gui_OutputFcn', @TOSAPRLAB4_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
function TOSAPRLAB4_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
guidata(hObject, handles);
function varargout = TOSAPRLAB4_OutputFcn(hObject, eventdata, handles)
varargout{1} = handles.output;
function pushbutton1_Callback(hObject, eventdata, handles)
interval=str2num(char(get(handles.edInterval,'String')));
f=(char(get(handles.edEquation,'String')));
[x,y]=fplot(f, interval);
handles.line=plot(x,y,'c-');
guidata(gcbo,handles);
hold on
function pushbutton2_Callback(hObject, eventdata, handles)
interval=str2num(char(get(handles.edInterval,'String')));
x1=interval(1);
x2=interval(2);
f=inline(char(get(handles.edEquation,'String')));
x=fminbnd(f,x1,x2);
y=f(x);
plot(x,y,'r.','MarkerSize',25);
function pushbutton3_Callback(hObject, eventdata, handles)
interval=str2num(char(get(handles.edInterval,'String')));
x1=interval(1);
x2=interval(2);
f=inline(char(get(handles.edEquation,'String')));
x=fzero(f,(x1+x2)/2);
y=f(x);
plot(x,y,'g.','MarkerSize',25);
function checkbox1_Callback(hObject, eventdata, handles)
if get(hObject,'Value')
set(gca,'XGrid','on')
else
set(gca,'XGrid','off')
end
function checkbox2_Callback(hObject, eventdata, handles)
if get(hObject,'Value')
set(gca,'YGrid','on')
else
set(gca,'YGrid','off')
end
function popupmenu1_Callback(hObject, eventdata, handles)
Num=get(hObject,'Value');
switch Num
case 1
set(handles.line,'LineStyle','-');
case 2
set(handles.line,'LineStyle','- -');
case 3
set(handles.line,'LineStyle',':');
case 4
set(handles.line,'LineStyle','-.');
end
function popupmenu1_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function popupmenu2_Callback(hObject, eventdata, handles)
Num=get(hObject,'Value');
switch Num
case 1
set(handles.line,'LineWidth',1);
case 2
set(handles.line,'LineWidth',2);
case 3
set(handles.line,'LineWidth',3);
case 4
set(handles.line,'LineWidth',4);
end
function popupmenu2_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function popupmenu3_Callback(hObject, eventdata, handles)
Num=get(hObject,'Value');
switch Num
case 1
set(handles.line,'Color','cyan');
case 2
set(handles.line,'Color','red');
case 3
set(handles.line,'Color','green');
case 4
set(handles.line,'Color','blue');
case 5
set(handles.line,'Color','magenta');
case 6
set(handles.line,'Color','yellow');
case 7
set(handles.line,'Color','white');
end
function popupmenu3_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit1_Callback(hObject, eventdata, handles)
function edit1_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edInterval_Callback(hObject, eventdata, handles)
function edInterval_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit2_Callback(hObject, eventdata, handles)
function edit2_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
Accepted Answer
More Answers (0)
Categories
Find more on Graphics Object Properties 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!