You are on page 1of 14

ESCUELA PROFESIONAL DE INGENIERIA MECÁNICA, MECÁNICA

ELECTRICA Y MECATRÓNICA

“MECÁNICA COMPUTACIONAL II”


I. GRUPO: : 12
II. TEMA : MATLAB
III. PROFESOR : ING. JUAN DIEGO CACERES HUAMAN
IV. ALUMNOS : SIERRA VALDIVIA BRYAN ALONZO

BERLY MARTIN CCAPA CALCINA


SILVA HENRY

2018
INTERFAZ GRÁFICA DE USUARIO EN MATLAB

INTRODUCCIÓN

GUIDE es un entorno de programación visual disponible en MATLAB para


realizar y ejecutar programas que necesiten ingreso continuo de datos. Tiene las
características básicas de todos los programas visuales como Visual Basic o Visual C++.

INICIO

Para iniciar nuestro proyecto, lo podemos hacer de dos maneras:

 Ejecutando la siguiente instrucción en la ventana de comandos:


>> guide
 Haciendo un click en el ícono que muestra la figura:

Ícono GUIDE.

Se presenta el siguiente cuadro de diálogo:

Ventana de inicio de GUI.


Se presentan las siguientes opciones:

a) Blank GUI (Default)


La opción de interfaz gráfica de usuario en blanco (viene predeterminada), nos
presenta un formulario nuevo, en el cual podemos diseñar nuestro programa.
b) GUI with Uicontrols
Esta opción presenta un ejemplo en el cual se calcula la masa, dada la densidad y
el volumen, en alguno de los dos sistemas de unidades. Podemos ejecutar este
ejemplo y obtener resultados.
c) GUI with Axes and Menu
Esta opción es otro ejemplo el cual contiene el menú File con las opciones Open,
Print y Close. En el formulario tiene un Popup menu, un push button y un objeto
Axes, podemos ejecutar el programa eligiendo alguna de las seis opciones que se
encuentran en el menú despegable y haciendo click en el botón de comando.
d) Modal Question Dialog
Con esta opción se muestra en la pantalla un cuadro de diálogo común, el cual
consta de una pequeña imagen, una etiqueta y dos botones Yes y No, dependiendo
del botón que se presione, el GUI retorna el texto seleccionado (la cadena de
caracteres ‘Yes’ o ‘No’).

Elegimos la primera opción, Blank GUI, y tenemos:

Entorno de diseño de GUI

La interfaz gráfica cuenta con las siguientes herramientas:

Alinear objetos.
Editor de menú.
Editor de orden de etiqueta.
Editor del M-file.
Propiedades de objetos.
Navegador de objetos.
Grabar y ejecutar (ctrl. + T).
Para obtener la etiqueta de cada elemento de la paleta de componentes ejecutamos:
File>>Preferentes y seleccionamos Show names in component palette. Tenemos la
siguiente presentación:

Entorno de diseño: componentes etiquetados.


PROPIEDADES DE LOS COMPONENTES

Cada uno de los elementos de GUI, tiene un conjunto de opciones que podemos
acceder con click derecho.

Opciones del componente.


Ejemplo 1

EL PROGRAMA EN UNA INTERFAZ GUIDE MUESTRA UNA IMAGEN Y DESPUES LE


PONE UN FLITRO

 Utilizamos push botton para crear 2 botones y tambien axis como se ve en la imagen
 Cambiamos el nombre de variable a los buttom como imagen y filtro respectivamente y
de igual manera con el axes 1 a pantallla

 En matlab se crea una codificacion por defecto la cual iremos modificando para llegar a
nuestro objetivo

function varargout = untitled1(varargin)


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

% Last Modified by GUIDE v2.5 13-Sep-2018 20:17:21

% Begin initialization code - DO NOT EDIT


gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @untitled1_OpeningFcn, ...
'gui_OutputFcn', @untitled1_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 untitled1 is made visible.


function untitled1_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 untitled1 (see VARARGIN)

% Choose default command line output for untitled1


handles.output = hObject;

% Update handles structure


guidata(hObject, handles);

% UIWAIT makes untitled1 wait for user response (see UIRESUME)


% uiwait(handles.figure1);

% --- Outputs from this function are returned to the command line.
function varargout = untitled1_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 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)

% --- Executes on button press in pushbutton2.


function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

 En la función de de botton imagen escribimos el comando

function imagen_Callback(hObject, eventdata, handles)


% hObject handle to imagen (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
im=imread('tiger.jpg');
imshow(im);
set(handles.pantalla,'UserData',im);

 y de la misma manera para utilizar un filtro

function filtro_Callback(hObject, eventdata, handles)


% hObject handle to filtro (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
sf=fspecial('laplacian', 0);
im=get(handles.pantalla,'UserData');
im2=imfilter(im,sf);
imshow(im2);

 utilizamos el get y set para guardar la variable y


después utilizarlo en otra función
EJEMPLO 2 MUESTRA 3 GRAFICAS Utilizaremos un boton para mandar a
graficar las diferentes funciones sobre los 3 axes.

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)
axes(handles.axes1);
x1 = [1:0.001:10];
x2 = 2-x1*3;
plot(x1,x2,'red','LineWidth', 2.5);

axes(handles.axes2);
x1 = [1:0.001:15];
x2 = x1*3/9;
plot(x1,x2,'LineWidth', 2.5);

axes(handles.axes3);
x1 = [1:0.001:20];
x2 = sin(x1);
plot(x1,x2, 'yellow', 'LineWidth', 2.5);

5.1 REALICE LA CONVERSIÓN DE GRADOS CELSIUS A GRADOS FAHRENHEIT


Y KELVIN

%EL PROGRAMA CONVIERTE LOS GRADOSCELCIUA A FARENHEIT Y KELVIN


%RESPECTIVAMENTE

PRIMER PEDIMOS QUE A LA VARIABLE A INGREWSEMOS UN DATOS

c=input('ingrese los grados celcius a convertir ');

UTILIZAMOS LOS LA VARIABLE PARA HACER LOS CALCULOS Y A ESOS DATOS LE


ASIGNAMOS OTRA VARIABLE

f=c*1.8+32
k=c+273.15

FINALMENTE MOSTRAMOS POR PANTALLA LA RESPUESTA

disp('la conversion de celcius a farenheit'); disp(f);


disp('la conversion de celcius a kelvin'); disp(k)

6.3 ESCRIBA UN PROGRAMA QUE PERMITA HALLAR LA HIPOTENUSA DE UN


TRIÁNGULO RECTÁNGULO. USE HELP PARA INVESTIGAR EL COMANDO
SQRT. NO OLVIDE QUE POTENCIA ES ^ (ALT + 94).
%Escriba un programa que permita hallar la hipotenusa de un triángulo
rectángulo. Use help
%para investigar el comando sqrt. No olvide que potencia es ^ (alt +
94).

PRIMERO PEDIMOS INGRESAR VALORES DE LOS CATETOS

b=input('ingrese EL VALOR DEL PRIMER CATETO: ');


a=input('ingrese EL VALOR DEL SEGUNDO CATETO: ');

EL COMADO HELP NOS AYUDA MOSTRANDO UNA DESCRIPCION DE LA FUNCION


EMPLEADO EN ESTE CASO SQRT

help sqrt

UTILIZAMOS LA FUNCION SQRT QUE DEVUELVE LA RAÍZ CUADRADA DE CADA


ELEMENTO Y ASI HALLAR LA HIPOTENUSA

h=sqrt(a^2+b^2)

POR ULTIMO MOSTRAMOS POR PANTAALLA LA RESPUESTA


disp('la hipotenusa del triangulo rectangulo es: '); disp(h)

You might also like