Error gui_mainfcn(gui_State, varargin{:});
139 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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
0 commentaires
Réponse acceptée
Voss
le 19 Nov 2022
The GUI opens ok, but the error I get when clicking the plot button is:
Reference to non-existent field 'edInterval'.
Error in TOSAPRLAB4>pushbutton2_Callback (line 41)
interval=str2num(char(get(handles.edInterval,'String')));
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in TOSAPRLAB4 (line 17)
gui_mainfcn(gui_State, varargin{:});
Error in
matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)TOSAPRLAB4('pushbutton2_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback
That's because the edit box edInterval is still called edit2 in the .fig file. (Similarly, edEquation is called edit1.)
To fix this, open the .fig file in GUIDE, double-click on edit2 and change its Tag to edInterval (and double-click on edit1 to change its Tag to edEquation). Then save the .fig file and close any running instance of the GUI (since it's a singleton), and run the m-file again.
2 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Migrate GUIDE Apps dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!