MATLAB GUI error Undefined function or variable 'zejecutar_Callback'.

9 views (last 30 days)
MATLAB GUI error Undefined function or variable 'zejecutar_Callback'. I made a GUI using guide, I get the error that 'zejecutar_Callback is undefined and I don´t know how to fix it.
Here is the code:
function varargout = gui2(varargin)
% GUI2 MATLAB code for gui2.fig
% GUI2, by itself, creates a new GUI2 or raises the existing
% singleton*.
%
% H = GUI2 returns the handle to a new GUI2 or the handle to
% the existing singleton*.
%
% GUI2('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in GUI2.M with the given input arguments.
%
% GUI2('Property','Value',...) creates a new GUI2 or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before gui2_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to gui2_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
end
% Edit the above text to modify the response to help gui2
% Last Modified by GUIDE v2.5 07-Nov-2018 19:43:36
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @gui2_OpeningFcn, ...
'gui_OutputFcn', @gui2_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 gui2 is made visible.
function gui2_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to gui2 (see VARARGIN)
% Choose default command line output for gui2
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes gui2 wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = gui2_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
function numeroreactores_Callback(hObject, eventdata, handles)
% hObject handle to numeroreactores (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of numeroreactores as text
% str2double(get(hObject,'String')) returns contents of numeroreactores as a double
% --- Executes during object creation, after setting all properties.
function numeroreactores_CreateFcn(hObject, eventdata, handles)
% hObject handle to numeroreactores (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function tiempo_Callback(hObject, eventdata, handles)
% hObject handle to tiempo (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of tiempo as text
% str2double(get(hObject,'String')) returns contents of tiempo as a double
% --- Executes during object creation, after setting all properties.
function tiempo_CreateFcn(hObject, eventdata, handles)
% hObject handle to tiempo (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function equilibrio_Callback(hObject, eventdata, handles)
% hObject handle to equilibrio (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of equilibrio as text
% str2double(get(hObject,'String')) returns contents of equilibrio as a double
% --- Executes during object creation, after setting all properties.
function equilibrio_CreateFcn(hObject, eventdata, handles)
% hObject handle to equilibrio (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function concentracion_Callback(hObject, eventdata, handles)
% hObject handle to concentracion (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of concentracion as text
% str2double(get(hObject,'String')) returns contents of concentracion as a double
% --- Executes during object creation, after setting all properties.
function concentracion_CreateFcn(hObject, eventdata, handles)
% hObject handle to concentracion (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function flujo_Callback(hObject, eventdata, handles)
% hObject handle to flujo (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of flujo as text
% str2double(get(hObject,'String')) returns contents of flujo as a double
% --- Executes during object creation, after setting all properties.
function flujo_CreateFcn(hObject, eventdata, handles)
% hObject handle to flujo (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function volumen_Callback(hObject, eventdata, handles)
% hObject handle to volumen (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of volumen as text
% str2double(get(hObject,'String')) returns contents of volumen as a double
% --- Executes during object creation, after setting all properties.
function volumen_CreateFcn(hObject, eventdata, handles)
% hObject handle to volumen (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in zejecutar.
function zejecutar_Callback(hObject, eventdata, handles)
% hObject handle to zejecutar (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global V k v N
N = str2double(get(handles.numeroreactores,'String'));
if N == 1 v = str2double(get(handles.flujo,'String'));
V = str2double(get(handles.volumen,'String'));
k = str2double(get(handles.concentracion,'String'));
x0 = str2double(get(handles.concentracion,'String'));
t0 = str2double(get(handles.tiempo,'String'));
[t, x] = ode45(@Proyecto_fun, t0, x0); CA1 = x(:,1)
CB1 = x(:,2)
axes(handles.grafico)
plot(t, x)
legend('CA_1', 'CB_1')
title('Concentración vs tiempo')
xlabel('t (min)')
ylabel('C (mol/dm^3)')
elseif N == 2
v = str2double(get(handles.flujo,'String'));
V = str2double(get(handles.volumen,'String'));
k = str2double(get(handles.concentracion,'String'));
x0 = str2double(get(handles.concentracion,'String'));
t0 = str2double(get(handles.tiempo,'String'));
[t, x] = ode45(@Proyecto_fun, t0, x0);
CA1 = x(:,1)
CB1 = x(:,2)
CA2 = x(:,3)
CB2 = x(:,4)
axes(handles.grafico)
plot(t, x)
legend('CA_1', 'CB_1', 'CA_2', 'CB_2')
title('Concentración vs tiempo')
xlabel('t (min)')
ylabel('C (mol/dm^3)')
elseif N == 3
v = str2double(get(handles.flujo,'String'));
V = str2double(get(handles.volumen,'String'));
k = str2double(get(handles.concentracion,'String'));
x0 = str2double(get(handles.concentracion,'String'));
t0 = str2double(get(handles.tiempo,'String'));
[t, x] = ode45(@Proyecto_fun, t0, x0);
CA1 = x(:,1)
CB1 = x(:,2)
CA2 = x(:,3)
CB2 = x(:,4)
CA3 = x(:,5)
CB3 = x(:,6)
axes(handles.grafico)
plot(t, x)
legend('CA_1', 'CB_1', 'CA_2', 'CB_2','CA_3', 'CB_3')
title('Concentración vs tiempo')
xlabel('t (min)')
ylabel('C (mol/dm^3)')
end
Here are the erros I get:
Undefined function or variable 'zejecutar_Callback'.
Error in gui_mainfcn (line 95) feval(varargin{:});
Error in gui2 (line 42) gui_mainfcn(gui_State, varargin{:});
Error in matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)gui2('zejecutar_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback.
  1 Comment
Walter Roberson
Walter Roberson on 17 Dec 2018
Is it possible that you started the gui by double clicking the fig file instead of running gui2.m ?

Sign in to comment.

Answers (1)

Cris LaPierre
Cris LaPierre on 17 Dec 2018
Edited: Cris LaPierre on 24 Dec 2018
I just formatted your code for you. Not sure how you copied it, but it had lost all its formatting. It appears that, perhaps, you lost the formatting on your side as well, as that error message would suggest the 'function' in front of zejecutar_Callback (line 172) got separated from it.
If I run your code as I have formatted it above, there are no issues.
If instead I run it formatted like this
% --- Executes on button press in zejecutar.
% function
zejecutar_Callback(hObject, eventdata, handles)
% hObject handle to zejecutar (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
I get the following error:
Undefined function or variable 'zejecutar_Callback'.
Error in updatePlot>listbox2_CreateFcn (line 173)
zejecutar_Callback(hObject, eventdata, handles)
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in updatePlot (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in
matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)...
An additional comment - your code had added an 'end' to each callback. That is unnecessary, and not how GUIDE creates the functions, so I have removed them.

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!