Matlab - Ayuda con una Gui

 
Vista:

Ayuda con una Gui

Publicado por Daniel (5 intervenciones) el 23/11/2021 18:22:25
Hola, soy nuevo en Matlab y estoy tratando de crear una Gui, para eso me estoy ayudando con un Manual de Interfaz Gráfica de Usuario en Matlab, pero el ejemplo que muestra no me corre para nada, así que no me funciona nada. Agradezco de ante mano la ayuda, acá le mando el código y el mensaje de error que me muestra en pantalla cuando lo corro:

function varargout = func_trig(varargin)
% FUNC_TRIG MATLAB code for func_trig.fig
% FUNC_TRIG, by itself, creates a new FUNC_TRIG or raises the existing
% singleton*.
%
% H = FUNC_TRIG returns the handle to a new FUNC_TRIG or the handle to
% the existing singleton*.
%
% FUNC_TRIG('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in FUNC_TRIG.M with the given input arguments.
%
% FUNC_TRIG('Property','Value',...) creates a new FUNC_TRIG or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before func_trig_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to func_trig_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

% Edit the above text to modify the response to help func_trig

% Last Modified by GUIDE v2.5 23-Nov-2021 15:09:01

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @func_trig_OpeningFcn, ...
'gui_OutputFcn', @func_trig_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 func_trig is made visible.
function func_trig_OpeningFcn(hObject, eventdata, handles, varargin)
handles.ejex=0:pi/360:2*pi;
y1=sin(2*pi*1*handles.ejex);
plot(handles.ejex,y1,'LineWidth',2);grid on;
axis([0 2*pi -1 1]);
% 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 func_trig (see VARARGIN)

% Choose default command line output for func_trig
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes func_trig wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = func_trig_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 popupmenu1_Callback(hObject, eventdata, handles)
fun =get(handles.sel,'Value');
switch fun
case 1
y1=sin(2*pi*1*handles.ejex);
plot(handles.ejex,y1,'LineWidth',2);grid on;axis([0 2*pi -1 1]);
case 2
y2=cos(2*pi*1*handles.ejex);
plot(handles.ejex,y2,'LineWidth',2);grid on;axis([0 2*pi -1 1]);
case 3
y3=sin(2*pi*1*handles.ejex)+cos(2*pi*1*handles.ejex);
plot(handles.ejex,y3,'LineWidth',2);grid on;
axis([0 2*pi min(y3) max(y3) ]);
end
guidata(hObject, handles);


function popupmenu1_CreateFcn(hObject, eventdata, handles)

% Hint: popupmenu 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

El mensage de error que muestra es el siguiente:
Reference to non-existent field 'sel'.

Error in func_trig>popupmenu1_Callback (line 81)
fun =get(handles.sel,'Value');

Error in gui_mainfcn (line 96)
feval(varargin{:});

Error in func_trig (line 42)
gui_mainfcn(gui_State, varargin{:});

Error in
@(hObject,eventdata)func_trig('popupmenu1_Callback',hObject,eventdata,guidata(hObject))


Error while evaluating uicontrol Callback
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder