Está en la página 1de 4

UANL

FACULTAD DE INGENIERIA MECANICA Y


ELECTRICA


ALUMNO: JAVIER EDUARDO QUIONES AMAYA

MATERIA: PROGRAMACION CON MATLAB

MATRICULA : 1493807

HORA: CURSO SABATINO V3-V5


USO DE GRAFICAS EN GUIS.



USO DE GRAFICAS EN GUIS
En este ejemplo presentamos como se puede realizar una interfase grafica conteniendo la grafica
dee una funcin.La funcin que deseamos graficar es:
Y(t)=sin(2

Donde f es la funcin seno
Para realizar nuestra GUI abrimos una nueva GUI usando GUIDE.A esta GUI le agregamos. A esta
GUI le agregamos ejes axes ,3 edit text, 4 static text, un radio button y 1 barra de deslizamiento
Las propiedades string de los static text
-RANGO DE TIEMPO
-TIEMPO INICIAL
-TIEMPO FINAL
-FRECUENCIA
Para el radio button, las propiedades string y tag las cambiamos a rejila.Para los edit ttext la
propiedad string la borramos para dejarla en blanco y el tag lo modificamos a lo siguiente:
Tiempo_inicial
Tiempo_final
Frecuencia
La propiedades de la barra de desplazamiento a:
Min 1
Max 10
Value 5
Tag barra
String en blanco



Se editan el callback de frecuencia

function Frecuencia_Callback(hObject, eventdata, handles)
% hObject handle to Frecuencia (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 Frecuencia as text
% str2double(get(hObject,'String')) returns contents of Frecuencia
as a double
% para obtener los rangos de tiempo
t1=str2num(get(handles.Tiempo_inicial,'string'));
t2=str2num(get(handles.Tiempo_final,'string'));
%formamos el vector de tiempos con 200 puntos
t=linspace(t1,t2,200);
%obtenemos el valor de la frecuencia y modificamos
%la barra de deslizamiento.
frec=str2num(get(handles.Frecuencia,'String'));
editamin=get(handles.Barra,'Min');
editamax=get(handles.Barra,'Max');
%checamos si el valor de la frecuencia es numerico
if isnumeric (frec) & length (frec)== 1 &...
frec >= editamin &...
frec <= editamax
set(handles.Barra,'Value',frec)
elseif frec < editamin
set(gcbo,'String',editamin);
set(handles.Barra,'Value',editamin);
frec=editamin;
elseif frec>editamax;
set(gcbo,'String',editamax);
frec=editamax;
end


Se editan el callback de la barra de deslizamiento
% --- Executes on slider movement.
function Barra_Callback(hObject, eventdata, handles)
% hObject handle to Barra (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
set(handles.Frecuencia,'String',get(gcbo,'Value'));
t1 = str2num(get(handles.Tiempo_inicial,'string'));
t2 = str2num(get(handles.Tiempo_final,'string'));
t = linspace(t1,t2,200);
frec=get(gcbo,'Value');
y=sin(2*pi*frec*t);
plot(t,y);
rejilla1=get(handles.Rejilla,'value');
if rejilla1==1
grid on
end

También podría gustarte