Matlab - Empezando con GUI

 
Vista:
sin imagen de perfil

Empezando con GUI

Publicado por Jacinto (37 intervenciones) el 03/06/2014 13:41:14
Hola, soy nuevo en esto de las GUIs, no consigo resolver un problema, aunque seguro que es muy sencillo, quiero hacer una GUI muy sencilla que invoque una función, y quiero introducir los parámetros de la función mediante la GUI, ¿como asocio estos parámetros a un edit text o un slider en el fichero .m? ¿Hay manera de hacerlo mediante algún menú de propiedades del editor de la GUI?

Muchas gracias.

Saludos.
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

Empezando con GUI

Publicado por Joaquín (50 intervenciones) el 03/06/2014 15:23:07
No es tan complicado... genera tu .fig sube tu fig. tu archivo m. y coloca tu función en la misma carpeta donde tengas tus archivos de GUI

Subelos al foro y así entre varios se te puede otorgar una ayuda mas específica

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
sin imagen de perfil

Empezando con GUI

Publicado por Jacinto (37 intervenciones) el 03/06/2014 16:52:06
Aquí subo mis archivos, lo que quiero es arrancar la función traffic y la función recibir introduciendo los parámetros en esta GUI y mostrar en ellas las dos gráficas que se generan.

Muchas gracias.

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
sin imagen de perfil

Empezando con GUI

Publicado por Jacinto (37 intervenciones) el 03/06/2014 18:14:04
He encontrado algo que me ha ayudado, pero me da error cuando lo ejecuto, lo que quiero es que las variables introducidas en los edit text sean las que se introduzcan como parámetro a la función que se ejecuta con el pushbutton, el código queda de la siguiente manera:

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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
function varargout = SimuladorARINC825(varargin)
%SIMULADORARINC825 M-file for SimuladorARINC825.fig
%      SIMULADORARINC825, by itself, creates a new SIMULADORARINC825 or raises the existing
%      singleton*.
%
%      H = SIMULADORARINC825 returns the handle to a new SIMULADORARINC825 or the handle to
%      the existing singleton*.
%
%      SIMULADORARINC825('Property','Value',...) creates a new SIMULADORARINC825 using the
%      given property value pairs. Unrecognized properties are passed via
%      varargin to SimuladorARINC825_OpeningFcn.  This calling syntax produces a
%      warning when there is an existing singleton*.
%
%      SIMULADORARINC825('CALLBACK') and SIMULADORARINC825('CALLBACK',hObject,...) call the
%      local function named CALLBACK in SIMULADORARINC825.M with the given input
%      arguments.
%
%      *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 SimuladorARINC825

% Last Modified by GUIDE v2.5 03-Jun-2014 17:56:02

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @SimuladorARINC825_OpeningFcn, ...
                   'gui_OutputFcn',  @SimuladorARINC825_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 SimuladorARINC825 is made visible.
function SimuladorARINC825_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   unrecognized PropertyName/PropertyValue pairs from the
%            command line (see VARARGIN)

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

% Update handles structure
guidata(hObject, handles);

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


% --- Outputs from this function are returned to the command line.
function varargout = SimuladorARINC825_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 nruido_Callback(hObject, eventdata, handles)
nruido=str2double(get(hObject,'String'))
% hObject    handle to nruido (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 nruido as text
%        str2double(get(hObject,'String')) returns contents of nruido as a double


% --- Executes during object creation, after setting all properties.
function nruido_CreateFcn(hObject, eventdata, handles)
% hObject    handle to nruido (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 notras_Callback(hObject, eventdata, handles)
notras=str2double(get(hObject,'String'))
% hObject    handle to notras (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 notras as text
%        str2double(get(hObject,'String')) returns contents of notras as a double


% --- Executes during object creation, after setting all properties.
function notras_CreateFcn(hObject, eventdata, handles)
% hObject    handle to notras (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 fs_Callback(hObject, eventdata, handles)
fs=str2double(get(hObject,'String'))
% hObject    handle to fs (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 fs as text
%        str2double(get(hObject,'String')) returns contents of fs as a double


% --- Executes during object creation, after setting all properties.
function fs_CreateFcn(hObject, eventdata, handles)
% hObject    handle to fs (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 fm_Callback(hObject, eventdata, handles)
fm=str2double(get(hObject,'String'))
% hObject    handle to fm (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 fm as text
%        str2double(get(hObject,'String')) returns contents of fm as a double


% --- Executes during object creation, after setting all properties.
function fm_CreateFcn(hObject, eventdata, handles)
% hObject    handle to fm (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)
tiempo=str2double(get(hObject,'String'))
% 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 prioridad_Callback(hObject, eventdata, handles)
prioridad=str2double(get(hObject,'String'))
% hObject    handle to prioridad (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 prioridad as text
%        str2double(get(hObject,'String')) returns contents of prioridad as a double


% --- Executes during object creation, after setting all properties.
function prioridad_CreateFcn(hObject, eventdata, handles)
% hObject    handle to prioridad (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 datos_Callback(hObject, eventdata, handles)
datos=str2double(get(hObject,'String'))
% hObject    handle to datos (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 datos as text
%        str2double(get(hObject,'String')) returns contents of datos as a double


% --- Executes during object creation, after setting all properties.
function datos_CreateFcn(hObject, eventdata, handles)
% hObject    handle to datos (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 pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
traffic (50, 5000, 3, 2, 46, 54, 2)
recibir(2)
% hObject    handle to pushbutton1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
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

Empezando con GUI

Publicado por Joaquín (50 intervenciones) el 03/06/2014 18:49:29
Que tal Jacinto, en primer lugar, hacer toda la redacción por este medio no se entendería muy bien, hice los comentarios en tu código, y te lo adjunto, espero te sirva y sea entendible...

También te adjunto dos codigos propios que hacen otras cosas diferentes, solo para que veas mas o menos como yo estructuro los míos

Y la imagen de como se editan los tags de todos los campos que se ingresan en la GUI


Espero tus comentarios..

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
sin imagen de perfil

Empezando con GUI

Publicado por Jacinto (37 intervenciones) el 03/06/2014 19:06:27
Muchas gracias, pero no puedo descargar tu archivo
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

Empezando con GUI

Publicado por Jacinto (37 intervenciones) el 03/06/2014 19:14:42
Sigue sin funcionarme el enlace, ¿podrías pegar en un mensaje los códigos con tus comentarios?

Muchas gracias.

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
sin imagen de perfil

Empezando con GUI

Publicado por Joaquín (50 intervenciones) el 03/06/2014 19:15:49
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
function varargout = SimuladorARINC825(varargin)
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @SimuladorARINC825_OpeningFcn, ...
                   'gui_OutputFcn',  @SimuladorARINC825_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
 
function SimuladorARINC825_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
guidata(hObject, handles);
 
function varargout = SimuladorARINC825_OutputFcn(hObject, eventdata, handles)
varargout{1} = handles.output;
 
 
function slider2_Callback(hObject, eventdata, handles)
function slider4_Callback(hObject, eventdata, handles)
function campo1_Callback(hObject, eventdata, handles)
function edit2_Callback(hObject, eventdata, handles)
function edit3_Callback(hObject, eventdata, handles)
function edit4_Callback(hObject, eventdata, handles)
function edit5_Callback(hObject, eventdata, handles)
function edit7_Callback(hObject, eventdata, handles)
function edit8_Callback(hObject, eventdata, handles)
 
%Te recomiendo, borra todos los comentarios propios de matlab, ya que solo
%ocupan lineas.... 
 
%Tambien nombra tus campos, osea, editar los tags de cada uno, para que tu
%mismo los puedes identificar, te recomiendo nombrarlos con el mismo nombre
%de tu código, para que no te revuelvas tanto
 
%El gui te genera automaticamente las function de cada campo editable,
%puedes dejar solamente la linea de callback.... y es una linea por cada
%campo editable (donde se ingresan variables)
 
 
%esta es la función del PUSHBUTTON 
function calcular_Callback(hObject, eventdata, handles)
 
%Cuando oprimes el pushbutton este TIENE QUE HACER ALGO... por lo que lo
%primero que haga es que llame los datos
 
 
%Esta es la linea para llamar datos, covertimos a numero lo que se
%introduce en el campo "campo1" y se le asigna a la variable "variable1"
variable1=str2num(get(handles.campo1,'String'));
 
%Por eso aquí la importancia de poner nombre a los campos, para que puedas
%asignarlos sin problemas y mas facilmente, por ejemplo tus lineas
%quedarían así... 
 
frecuencia=str2num(get(handles.frecuencia,'String'));
 
%Ahora bien en este espacio, despues de llamar y asignar todas tus
%variables aqui haces llamada a la función de tu preferencia, igual que
%como se llama una funcion en cualquier otro archivo m
 
A = traffic (fs, fm, nruido, notras, prioridad, datos, tiempo
 
 
%Y lo que te resta por hacer, es asignar tus imagenes a los axes de tu GUI 
 
 
imshow(huella1,'Parent',handles.axes1);
%imshow(tuvariable,'Parent',handles.tagdeleje);
 
 
 
 
 
%Ahora bien... las llamadas de datos anteriores SON SOLO para edit text, si
%tienes otros editables como por ejemplo un "popup menu" la llamada de
%datos es diferente, tienes que asignar el valor de la variable en el mismo
%call back de dicho campo, y despues "exportar" ese valor, te muestro como
 
 
function conductor_Callback(hObject, eventdata, handles)
val=get(hObject,'value');
    switch val
        case 2
            k=5.8336;    %kCal/m-min-°C
            Rho=8915;    %Kg/m3
            Cp=0.092;    %kCal/kg-°C
        case 3
            k=3.43306;   %kCal/m-min-°C
            Rho=2705;    %Kg/m3
            Cp=0.215;    %kCal/kg-°C
    end
       handles.k=k;
       handles.Rho=Rho;
       handles.Cp=Cp;
       guidata(hObject, handles);
 
       %esas ultimas 4 lineas de la 101 a la 104 es para exportar el valor
       %de tus variables, en este caso mis variables son k, Rho y Cp....
       %ahora bien, despues hay que IMPORTRLAS en nuestro callback de
       %pushbutton
 
 
 
       %Si volvemos a poner la linea de la llamada al presionar el boton,
       %al inicio de tu callback de tu push button, debes llamar TODAS las
       %variables! para que así pueda correr tu código y no te falte
       %ninguna variable 
       function calcular_Callback(hObject, eventdata, handles)
 
k=handles.k;
Rho=handles.Rho;
Cp=handles.Cp;
 
%Y así, cuantas variables que no sean de un edit tex, hayas asignado, ahora
%si, en tus funciones o codigo tus variables k, rho y cp (en este caso) ya
%existen y tienen un valor
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
1
Comentar
sin imagen de perfil

Empezando con GUI

Publicado por Jacinto (37 intervenciones) el 03/06/2014 19:56:10
Según me indicas el código me queda así:

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
function varargout = SimuladorARINC825(varargin)
 
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @SimuladorARINC825_OpeningFcn, ...
                   'gui_OutputFcn',  @SimuladorARINC825_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
 
 
 
function SimuladorARINC825_OpeningFcn(hObject, eventdata, handles, varargin)
 
handles.output = hObject;
 
guidata(hObject, handles);
 
 
 
function varargout = SimuladorARINC825_OutputFcn(hObject, eventdata, handles)
 
varargout{1} = handles.output;
 
 
 
function nruido_Callback(hObject, eventdata, handles)
function notras_Callback(hObject, eventdata, handles)
function fs_Callback(hObject, eventdata, handles)
function fm_Callback(hObject, eventdata, handles)
function tiempo_Callback(hObject, eventdata, handles)
function prioridad_Callback(hObject, eventdata, handles)
function datos_Callback(hObject, eventdata, handles)
function Simular_Callback(hObject, eventdata, handles)
 
fs=str2num(get(handles.fs,'String'));
fm=str2num(get(handles.fm,'String'));
nruido=str2num(get(handles.nruido,'String'));
notras=str2num(get(handles.notras,'String'));
prioridad=str2num(get(handles.prioridad,'String'));
datos=str2num(get(handles.datos,'String'));
tiempo=str2num(get(handles.tiempo,'String'));
 
traffic (fs, fm, nruido, notras, prioridad, datos, tiempo)
recibir(tiempo)


%Y APARECE EL SIGUIENTE ERROR:

Error using str2num (line 33)
Requires string or character array input.

Error in SimuladorARINC825>Simular_Callback (line 46)
fs=str2num(get(handles.fs,'String'));

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

Error in SimuladorARINC825 (line 18)
gui_mainfcn(gui_State, varargin{:});

Error in
@(hObject,eventdata)SimuladorARINC825('Simular_Callback',hObject,eventdata,guidata(hObject))


Error while evaluating uicontrol Callback
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

Empezando con GUI

Publicado por Joaquín (50 intervenciones) el 03/06/2014 21:49:43
Estás capturando valores en tus campos? Que tipo de valores son? deben ser numéricos y no contener letras o símbolos

Vuelve a subir tu código actualizado por favor

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
sin imagen de perfil

Empezando con GUI

Publicado por Jacinto (37 intervenciones) el 04/06/2014 12:06:42
Sólo son números enteros lo que introduzco:


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

Empezando con GUI

Publicado por Joaquín (50 intervenciones) el 04/06/2014 15:30:57
Sube tu código, probablemente hay una llamada que no se esté haciendo bien


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
sin imagen de perfil

Empezando con GUI

Publicado por Jacinto (37 intervenciones) el 04/06/2014 16:32:39
Es el mismo que hay 3 comentarios más arriba.

Muchas gracias.

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
sin imagen de perfil

Empezando con GUI

Publicado por Joaquín (50 intervenciones) el 04/06/2014 16:58:48
Pero no tengo tu fig. actualizado, de preferencia sube el otra vez la carpeta, pero actualizada...

Saludos
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
1
Comentar
sin imagen de perfil

Empezando con GUI

Publicado por Jacinto (37 intervenciones) el 04/06/2014 19:01:42
Ya lo tengo, el problema era que tenía que poner str2double donde ponía str2num, ahora lo que me fallan son los gráficos, una de las funciones que invoco invoca otra cuyo gráfico es el único que aparece, pero los de ambas funciones, que son los que deberían aparecer en los ejes no salen. ¿Alguna idea? ¿Y para ajustar los valores de los edit text mediante slider, pero que vayan vinculados a los edit text?

Y creo que con esto ya tenía todo.

Muchas gracias por la ayuda!!!
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

Empezando con GUI

Publicado por Joaquín (50 intervenciones) el 04/06/2014 21:33:50
mmmmm lo de los sliders te lo debo, nunca he puesto un slider la verdad.... te recomiendo tambien poner static text, arriba de tus campos, para que el usuario pueda a que se refiere cada campo y que debe de ingresar, a la derecha pones unidades o cosas asi ...





imshow(huella1,'Parent',handles.axes1);

Esta es la linea con la que yo colocaba una imagen en mis ejes, la pones hasta el final de la acción del pushbotton...

huella1 era mi imagen, supongo que si asignas tu grafica a alguna variable, la puedes colocar ahí.... y axes1 es el tag del eje donde yo quiero que se muestre...

Que bueno que te han servido los comments

Saludos
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
1
Comentar
sin imagen de perfil

Empezando con GUI

Publicado por Jacinto (37 intervenciones) el 10/06/2014 17:52:59
Una vez más recurro a su ayuda, ya que me está salvando la vida. Respecto a los gráficos: como me indica, así dibujo las funciones que introduzco como parámetro en el gráfico, pero lo que quiero no es dibujar estas funciones exactamente, si no unas gráficas que se generan cuando se ejecutan estas, que no son exactamente la respuesta de la función, no sé si me he explicado bien. Es decir, ejecutando estas funciones, se generan en figura 1 y figura 2 unos gráficos, que son los que quiero que me aparezcan en los gráficos de la GUI (funciones traffic y recibir). Dejo mis códigos por si son necesarios.

Muchas gracias.

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
sin imagen de perfil

Empezando con GUI

Publicado por Joaquín (50 intervenciones) el 10/06/2014 20:31:14
Que tal Jacinto.... pues viendo tus funciones...

% Generar trafico genera la trama que contiene los datos junto a otras
% tramas definidas y junto a ruido

function A = traffic (fs, fm, nruido, prioridad, tiempo, priomin, priomax, porcentaje)

% Generamos la matriz con las tramas de los mensajes:

B = generar_trama_mensajes(fs, fm, prioridad, tiempo);

% Generamos la matriz con los mensajes adicionales:

C = generar_tramas_erroneas (porcentaje);

% Generamos la matriz con el ruido:

D = generar_ruido (nruido, tiempo, priomin, priomax);

% Juntamos la tres matrices en una sola:

A = [B; C; D];

% Ordenamos las tramas según su tiempo:

A = sortrows (A, 15); save variables3 A;

x = A (:, 11);

y = A (:, 15);

figure(1);

plot (y, x)


Lo que puedes hacer es declarar una variable que contenga la gráfica o dibujo que deseas, si en este caso es figure(1)... simplemente

imagen1=(figure(1), y,x) o lo que corresponda, en mi lógica es como guardar la gráfica como una imagen....

despues simplemente lo asignas al eje que corresponda

imshow(imagen1,'Parent',handles.axes1); ..... aces1, axes2, axes3.... o el tag que tenga tu axes.... que en este caso es axes1 y axes2



Otra cosa meramente visual.... elimina el string de tus edit text... dejalos en blanco, para que no aparezca esa leyenda de "edit text"











También veo que lo que dice "prioridad" no es un edit text sino un static text donde se piensa ingresar el valor... no sé si lo notaste





Si lo de asignar tu grafica a una variable no funciona, dejame lo reviso... pero es lo primero que se me ocurre, nombrar la grafica como variable.....

Saludos
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
1
Comentar
sin imagen de perfil

Empezando con GUI

Publicado por Jacinto (37 intervenciones) el 11/06/2014 18:29:46
Muchas gracias, tengo que terminar mi TFG esta semana y me está ayudando bastante más que mi tutor, suerte que haya gente como usted, y ahora, fuera de las GUIs, ya que ha visto mis códigos, en los que pretendo simular un bus de comunicaciones, le estaría eternamente agradecido si le echara un vistazo al siguiente problema:

%Ejecuto la función traffic, que simula una serie de tramas con sus tiempos de emisión, con los siguientes parámetros:

traffic (50, 500, 8, 54, 2, 14, 62, 5)

%Y una vez tengo la matriz que representa el tráfico en el bus ejecuto recibir, que lo que hace es despachar las tramas
% según prioridad y orden de llegada, esta función funcionaba para un periodo de la señal, pero ahora que lo hago
% para un tiempo dado, si ejecuto:

recibir(54)

%Aparece el siguiente error:

Index exceeds matrix dimensions.

Error in recibir (line 31)
if (A((b+1),15) <= tf) % Comprobamos si t es menor que tf

No consigo averiguar porqué se da.

Muchas gracias.

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
sin imagen de perfil

Empezando con GUI

Publicado por Jacinto (37 intervenciones) el 24/06/2014 18:32:52
Hola de nuevo, en una interfaz tengo un push button que me lleva a otra subinterfaz con edit text cuyos valores quiero pasar a la interfaz principal ¿cómo podría hacer esto?

Muchas gracias.

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
sin imagen de perfil

Empezando con GUI

Publicado por Joaquín (50 intervenciones) el 24/06/2014 18:51:33
No estoy totalmente seguro, pero es muy similar, debes EXPORTAR ESAS VARIABLES y luego importarlas... similar a lo sig.

handles.k=k;
handles.Rho=Rho;
handles.Cp=Cp;
guidata(hObject, handles);


k=handles.k;
Rho=handles.Rho;
Cp=handles.Cp;

Saludos

Espero que vayas bien con tu programa :)
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

Empezando con GUI

Publicado por Jacinto (37 intervenciones) el 24/06/2014 19:03:03
Muchas gracias, pero perdón ¿podrías explicarlo un poco mejor? ¿dónde pongo esto, en la principal o en la subinterfaz? ¿tengo que llamar a la interfaz principal desde la secundaria? Lo único que consigo es que se abra la ventana, introduzco los datos y al cerrarla desaparecen, ¿tengo que poner otro botón para cerrar la interfaz que haga que se pasen las variables?

Muchísimas gracias.

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
sin imagen de perfil

Empezando con GUI

Publicado por Joaquín (50 intervenciones) el 24/06/2014 19:29:01
En la "secundaria" debes exportar la variable (dentro de la rutina que la genere) y en la "principal" debes importarla, en la rutina u operación donde debe ser llamada.... eso si tienes mas de un push buttom ...

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
sin imagen de perfil

Empezando con GUI

Publicado por Jacinto (37 intervenciones) el 24/06/2014 19:55:06
Me temo que no funciona, lo que estoy haciendo es, en cada subfunción, en la que tengo unos edit text y un push button, cuando pulso el push button convierto en números los valores y luego los importo con lo que me ha dicho de

handles.variable=variable;
guidata(hObject, handles);

% Y luego en la interfaz principal, cuando pulso el pushbutton que quiero que las use:

variable=handles.variable;

¿es así?

Muchas gracias de nuevo.
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

Empezando con GUI

Publicado por Joaquín (50 intervenciones) el 24/06/2014 19:58:57
Es correcto, y así no te funciona?? :S

mmmmm... puedes subir tu código, a lo mejor estoy omitiendo algo...

Saludos
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
1
Comentar
sin imagen de perfil

Empezando con GUI

Publicado por Joaquín (50 intervenciones) el 24/06/2014 21:44:13
Esto es algo similar a lo que buscas..

http://www.lawebdelprogramador.com/foros/Matlab/1134866-Pasar_valor_de_una_variable_de_una_gui_a_otra.html
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
1
Comentar
sin imagen de perfil

Empezando con GUI

Publicado por Jacinto (37 intervenciones) el 25/06/2014 18:59:09
Muchísimas gracias, finalmente lo he hecho guardando las variables en archivos .mat, que era lo que no quería hacer, pero no he encontrado otra manera y tampoco creo que sea tan descabellado. Por último, y ya con esto podemos dejar zanjada la cuestión: ¿Puedo limitar los valores de las variables a introducir?

Muchas gracias de nuevo!!

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