Matlab - Problema con gui de matlab

 
Vista:
sin imagen de perfil

Problema con gui de matlab

Publicado por Juan Camilo (4 intervenciones) el 22/03/2017 04:30:57
buenas gente

Tengo el siguiente problema con la interfaz gráfica de matlab
quiero cambiar la imagen de fondo cuando pulse una tecla y para eso use este codigo

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
function varargout = segundo(varargin)
% SEGUNDO MATLAB code for segundo.fig
%      SEGUNDO, by itself, creates a new SEGUNDO or raises the existing
%      singleton*.
%
%      H = SEGUNDO returns the handle to a new SEGUNDO or the handle to
%      the existing singleton*.
%
%      SEGUNDO('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in SEGUNDO.M with the given input arguments.
%
%      SEGUNDO('Property','Value',...) creates a new SEGUNDO or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before segundo_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to segundo_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 segundo

% Last Modified by GUIDE v2.5 14-Mar-2017 11:52:23

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @segundo_OpeningFcn, ...
                   'gui_OutputFcn',  @segundo_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 segundo is made visible.
function segundo_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 segundo (see VARARGIN)

% Choose default command line output for segundo
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
set(handles.figure1,'WindowKeyPressFcn',@cal2)
global b r a g f m d c
b='b';
a='a';
g='g';
f='f';
m='m';
d='d';
c='c';
r=0;

% UIWAIT makes segundo wait for user response (see UIRESUME)
% uiwait(handles.figure1);
function cal2(h,e,hObject, eventdata, handles)
global b r a g f m d c
if strcmp(e.Key,b)
    %imagen de fondo
    w=imread('imagenes\si.PNG');
    axes(handles.axes1)
    image(w)
    axis off
end
 
 
% --- Outputs from this function are returned to the command line.
function varargout = segundo_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;
 
 
% --- Executes on button press in MASTER.


y me arroja el siguiente error

Error using segundo>cal2 (line 77)
Not enough input arguments.

Error while evaluating Figure WindowKeyPressFcn

al presionar la tecla 'b' que es con la que estaba probando el cambio de fondo
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
sin imagen de perfil

Problema con gui de matlab

Publicado por Juan Camilo (4 intervenciones) el 22/03/2017 06:26:04
Hola Jesus, gracias por responder.
Probé lo que sugeriste pero no dio resultado, arrojo el mismo error.
Creo que en la función cal2 falta una variable. Tal vez sepas cual es?

Saludos
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
Imágen de perfil de JESUS DAVID ARIZA ROYETH
Val: 3.309
Plata
Ha mantenido su posición en Matlab (en relación al último mes)
Gráfica de Matlab

Problema con gui de matlab

Publicado por JESUS DAVID ARIZA ROYETH (1818 intervenciones) el 22/03/2017 07:07:07
no falta ninguna , el problema es del guide al contrario al parecer está sobrando handles, pero si lo quitas te va a salir otro error que no reconoce handles.axes1, debes ir al editor de guide en properties en callback y dejar la función por defecto WindowKeyPressFcn
1
function figure1_WindowKeyPressFcn(h, e, handles)
luego copias el código de esa función en esa o adjunta el archivo y se te hace la corrección
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
sin imagen de perfil

Problema con gui de matlab

Publicado por Juan Camilo (4 intervenciones) el 23/03/2017 03:18:27
Encontraste lo que necesitaba, ya todo funciona a la perfección.
Gracias por la ayuda.

Saludos
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar