Filter löschen
Filter löschen

Getting Error in Matlab GUIDE

3 Ansichten (letzte 30 Tage)
qiana curcuru
qiana curcuru am 23 Feb. 2018
Kommentiert: Walter Roberson am 24 Jul. 2022
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

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 23 Feb. 2018
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 Kommentare
MAYUR KULAM
MAYUR KULAM am 24 Jul. 2022
Bearbeitet: MAYUR KULAM am 24 Jul. 2022
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 am 24 Jul. 2022
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)

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (2)

SRT HellKitty
SRT HellKitty am 23 Feb. 2018
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 am 23 Feb. 2018
Bearbeitet: Image Analyst am 23 Feb. 2018
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 Kommentare
qiana curcuru
qiana curcuru am 23 Feb. 2018
I tried that, but it still didn't work, but I attached the original .m file. Thank you!!
Image Analyst
Image Analyst am 23 Feb. 2018
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.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Migrate GUIDE Apps finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by