Matlab - Buttom group

 
Vista:

Buttom group

Publicado por JJ (12 intervenciones) el 10/02/2012 19:06:16
Tengo un buttom group con 3 opciones, según que botón escojas se le da un valor a un parámetro A y B. Después, al pulsar un pushboton quiero que me aparezca una gráfica. Os pongo el código correspondiente:

% --- Executes when selected object is changed in uipanel1.
function uipanel1_SelectionChangeFcn(hObject, eventdata, handles)
% hObject handle to the selected object in uipanel1
% eventdata structure with the following fields (see UIBUTTONGROUP)

if (hObject==handles.uno)
A=1;
B=5;
elseif hObject==handles.dos
A=2;
B=3;
elseif hObject==handles.tres
A=3;
B=1;
end
% EventName: string 'SelectionChanged' (read only)
% OldValue: handle of the previously selected object or empty if none was selected
% NewValue: handle of the currently selected object
% handles structure with handles and user data (see GUIDATA)


% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% 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)
x=[A A+1 A+2];
y=[B 0 B];
axes(handles.axes1)
plot(x.y)

Me indica que no conocen el valor de A y B. ¿por qué?
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
Imágen de perfil de JOSE JEREMIAS CABALLERO
Val: 6.975
Oro
Ha mantenido su posición en Matlab (en relación al último mes)
Gráfica de Matlab

Buttom group

Publicado por JOSE JEREMIAS CABALLERO (5917 intervenciones) el 10/02/2012 19:30:11
Hola JJ.
Hice unos arreglos, a tu codigo que acabas de copiar, me gustaria ver tu codigo completo.
Porque derepente hay mas errores, por motivos de tag y otros variables.
Apesar de los arreglos que te acabo hacer a tu codigo, aun sigue fallando, entonces si desea me envias tu codigo ami correo para poder verlo y filtrarte, ya que un interface tiene dos aspectos, un archivo *.fig y un archivo *.m y eso hay veces ocaciona que uno no pueda dar una respuesta correcta a las preguntas sobre guide.
Porque ademas reproducir el guide que estas haciendo implica tiempo.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
function uipanel1_SelectionChangeFcn(hObject, eventdata, handles)
global A B
if hObject==handles.uno
A=1; B=5;
elseif hObject==handles.dos
A=2;  B=3;
elseif hObject==handles.tres
A=3; B=1;
end
guidata(hObject, handles);
 
 
 
function pushbutton1_Callback(hObject, eventdata, handles)
global A B
x=[A A+1 A+2];
y=[B 0 B];
axes(handles.axes1)
plot(x,y)
guidata(hObject, handles);



1
2
3
4
5
6
7
Saludos.
JOSE JEREMIAS CABALLERO

Servicios de programacion matlab

Asesor de Proyectos con Matlab
programador en matlab
"Detalladar sus preguntas, para recibir respuestas acertadas"
jjcc94@hotmail.com ='/img/emoticons/teeth.gif' width='22' height='22' border='0' />
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

Buttom group

Publicado por JJ (12 intervenciones) el 10/02/2012 19:39:21
Muchas gracias Jose por contestar, este es el código:
function varargout = untitled(varargin)
% UNTITLED M-file for untitled.fig
% UNTITLED, by itself, creates a new UNTITLED or raises the existing
% singleton*.
%
% H = UNTITLED returns the handle to a new UNTITLED or the handle to
% the existing singleton*.
%
% UNTITLED('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in UNTITLED.M with the given input arguments.
%
% UNTITLED('Property','Value',...) creates a new UNTITLED or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before untitled_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to untitled_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 untitled

% Last Modified by GUIDE v2.5 10-Feb-2012 18:18:00

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

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

% Update handles structure
guidata(hObject, handles);

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


% --- Outputs from this function are returned to the command line.
function varargout = untitled_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 when selected object is changed in uipanel1.
function uipanel1_SelectionChangeFcn(hObject, eventdata, handles)
% hObject handle to the selected object in uipanel1
% eventdata structure with the following fields (see UIBUTTONGROUP)
if (hObject==handles.uno)
A=1;
B=5;
elseif hObject==handles.dos
A=2;
B=3;
elseif hObject==handles.tres
A=3;
B=1;
end
% EventName: string 'SelectionChanged' (read only)
% OldValue: handle of the previously selected object or empty if none was selected
% NewValue: handle of the currently selected object
% handles structure with handles and user data (see GUIDATA)


% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% 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)
x=[A A+1 A+2];
y=[B 0 B];
axes(handles.axes1)
plot(x.y)
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 Dave
Val: 497
Ha mantenido su posición en Matlab (en relación al último mes)
Gráfica de Matlab

Buttom group

Publicado por Dave (1094 intervenciones) el 10/02/2012 19:54:01
Hola JJ;

Te dejo una segmento de una situación similar:

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
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
%
% Una opción es crear una vector de radiobutton y luego evaluar cual fue seleccionado
nf=zeros(1,3);
nf(1)=get(handles.radiobutton_FUMB,'Value');
nf(2)=get(handles.radiobutton_FDIF,'Value');
nf(3)=get(handles.radiobutton_FNEW,'Value');
ind_nf=find(nf==1);
 
ind_nv = get(handles.text_value,'string');
 
switch ind_nf
    case 1,
        if ~isempty(ind_nv)
            [SALVAR,DATE]=filter_rangos_posible(VAR,DATE,ind_nv);
            disp('Evalua Filtro de valores posibles')
        else
            msgbox('Seleccione al menos una variable','Aviso importante','Warn')
        end
    case 2,
        if ~isempty(ind_nv)
            [SALVAR,DATE]=filter_diferential(VAR,DATE,ind_nv);
            disp('Evalua Filtro Diferencial')
        else
            msgbox('Seleccione al menos una variable','Aviso importante','Warn')
        end
    case 3,
        if ~isempty(ind_nv)
           [SALVAR,DATE]=filter_nuevo(VAR,DATE);
           disp('Evalua Filtro Nuevo')
        else
            msgbox('Seleccione al menos una variable','Aviso importante','Warn')
        end
end



Espero que sea de alguna ayuda.

Saludos
Dave Correa
[email protected]
Servicios de Programación Matlab
http://fismatlab.blogspot.com/
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 JOSE JEREMIAS CABALLERO
Val: 6.975
Oro
Ha mantenido su posición en Matlab (en relación al último mes)
Gráfica de Matlab

Buttom group

Publicado por JOSE JEREMIAS CABALLERO (5917 intervenciones) el 10/02/2012 21:59:39
Hola JJ.

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
function varargout = button_group_caballero(varargin)
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @button_group_caballero_OpeningFcn, ...
                   'gui_OutputFcn',  @button_group_caballero_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 button_group_caballero_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
guidata(hObject, handles);
 
function varargout = button_group_caballero_OutputFcn(hObject, eventdata, handles)
varargout{1} = handles.output;
 
function uipanel1_SelectionChangeFcn(hObject, eventdata, handles)
global A B
if hObject==handles.uno
A=1;   B=5;
elseif hObject==handles.dos
A=2;   B=3;
elseif hObject==handles.tres
A=3;   B=1;
end
 
function pushbutton1_Callback(hObject, eventdata, handles)
global A B
x=[A A+1 A+2];
y=[B 0 B];
axes(handles.axes1)
plot(x,y)

Este codigo funciona correctamente.
Dereepente el error debe de estar en la creacion de tu guide. En tu guide, tiene que estar activado el primer boton, automaticamente. Y si no esta activado, entonces el error esta alli.
Mira este video, te va a ayudar mucho.




Saludos.
JOSE JEREMIAS CABALLERO

Servicios de programacion matlab


Asesor de Proyectos con Matlab
programador en matlab
"Detalladar sus preguntas, para recibir respuestas acertadas"
[email protected]
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