Getting Error in Matlab GUIDE

조회 수: 1 (최근 30일)
qiana curcuru
qiana curcuru 2018년 2월 23일
댓글: Walter Roberson 2022년 7월 24일
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에서 Data Type Identification에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by