Getting Error in Matlab GUIDE

3 次查看(过去 30 天)
I just want to press a button and have 'ok' print to an edit field, but I keep getting the following error after I click the button:
Undefined function or variable 'pushbutton1_Callback'.
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in PME_app2 (line 17)
gui_mainfcn(gui_State, varargin{:});
Error in
matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)PME_app2('pushbutton1_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback.
Code Below
function varargout = PME_app2(varargin)
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @PME_app2_OpeningFcn, ...
'gui_OutputFcn', @PME_app2_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
% --- Executes just before PME_app2 is made visible.
function PME_app2_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
guidata(hObject, handles);
end
% --- Outputs from this function are returned to the command line.
function varargout = PME_app2_OutputFcn(hObject, eventdata, handles)
varargout{1} = handles.output;
end
function pushbutton1_Callback(hObject, eventdata, handles)
set(handles.edit1,'ok')
end
% --- Executes during object creation, after setting all properties.
function pushbutton1_CreateFcn(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
end

采纳的回答

Walter Roberson
Walter Roberson 2018-2-23
Your code for function pushbutton1_Callback would either have to be inside PME_app2.m or else it would have to be in its own pushbutton1_Callback.m file in order to be found.
  27 个评论
MAYUR KULAM
MAYUR KULAM 2022-7-24
编辑:MAYUR KULAM 2022-7-24
when i write the code in the function Enc_Char and Dec_Char and call it in imp.m then the above error occurs saying Execution of script Enc_Char as a function is not supported is there anyother way i can use it in my main code itself
Walter Roberson
Walter Roberson 2022-7-24
Remember that in MATLAB, there are three different types of .m files:
  • a file in which the first non-comment is "function" is a function file
  • a file in which the first non-comment is "classdef" is a class definition
  • all other .m files are "script" files
The message is telling you that Dec_Char is a script file. It either has no "function" at all or else it has some code before the "function" statement. You need to fix the file to be a function file. (A file that contains only comments would also be considered a script file)

请先登录,再进行评论。

更多回答(2 个)

SRT HellKitty
SRT HellKitty 2018-2-23
I'm not sure this will fix the error you are encountering, but when you set a textbox you need to use this context;
set(handles.edit1,'String','ok')

Image Analyst
Image Analyst 2018-2-23
编辑:Image Analyst 2018-2-23
In GUIDE, right click on the button and say "View Callbacks -> Callback". This will create the callback function that you need, and which your program is trying to execute but that does not exist yet (until you create it).
And get rid of the "end" statements in PME_app2_OpeningFcn() and pushbutton1_Callback().
If that doesn't work, also attach the .m file so we can fix it.
  2 个评论
qiana curcuru
qiana curcuru 2018-2-23
I tried that, but it still didn't work, but I attached the original .m file. Thank you!!
Image Analyst
Image Analyst 2018-2-23
Well it did work because the "ends" were making your function a nested function and you told Walter that once you fixed that, it worked.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Migrate GUIDE Apps 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by