Está en la página 1de 13

GUÍA DE LABORATORIO 03 MECANICA COMPUTACIONAL PAG 1/ 17

II
UNIVERSIDAD CATÓLICA DE SANTA MARÍA
ESCUELA PROFESIONAL DE INGENIERÍA MECÁNICA,
MECÁNICA ELÉCTRICA Y MECATRÓNICA
CÓDIGO : 4E04128
GUIA DE LABORATORIO Nro. 03
ASIGNATURA : MECANICA COMPUTACIONAL II
PRIMERA FASE Docentes:
Ing. Henry Christian Zegarra
GUIDE y su entorno de desarrollo. Programación de Gago. Ing. Juan Carlos Cuadros.
Interfaces Gráficas Ing. Christiam Collado Oporto.

Puntos:
Nombres y apellidos: Lira Monterola Steven luis
Código: Grupo: 09
2018248221

I. DESARROLLO DEL INFORME


I. OBJETIVOS DE LABORATORIO
a. Conocer el entorno GUIDE de MATLAB para crear Interfaces Gráficas.
b. Conocer y manejar los componentes principales de una GUIDE.
c. Conocer y manejar los controles principales de una GUIDE
d. Desarrollar una aplicación básica GUIDE.

II. HERRAMIENTAS
1. Computador con Matlab 2017.

2. Apuntes y Guía de laboratorio.

II.
Para cada una de las preguntas, consigne los pasos seguidos para su solución de
problema con Matlab.
6.1 Modifique el GUI calculadoraXY.fig que permita la selección del modo Estándar y
Científico. Este atento a los requerimientos solicitados por el usuario para el
funcionamiento del GUI.

Mecánica Computacional II -
2019
GUÍA DE LABORATORIO 03 MECANICA COMPUTACIONAL PAG 2/ 17
II

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

% Last Modified by GUIDE v2.5 01-Oct-2019 00:37:13

% Begin initialization code - DO NOT EDIT


gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @Calculadora_LiraSteven_OpeningFcn, ...
'gui_OutputFcn', @Calculadora_LiraSteven_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

Mecánica Computacional II -
2019
GUÍA DE LABORATORIO 03 MECANICA COMPUTACIONAL PAG 3/ 17
II
% --- Executes just before Calculadora_LiraSteven is made visible.
function Calculadora_LiraSteven_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 Calculadora_LiraSteven (see VARARGIN)

% Choose default command line output for Calculadora_LiraSteven


handles.output = hObject;

% Update handles structure


guidata(hObject, handles);

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


% uiwait(handles.figure1);

% --- Outputs from this function are returned to the command line.
function varargout = Calculadora_LiraSteven_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 pantalla_Callback(hObject, eventdata, handles)


% hObject handle to pantalla (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 pantalla as text


% str2double(get(hObject,'String')) returns contents of pantalla as a double

% --- Executes during object creation, after setting all properties.


function pantalla_CreateFcn(hObject, eventdata, handles)
% hObject handle to pantalla (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 pb1.


function pb1_Callback(hObject, eventdata, handles)
% boton 1
s=get(handles.pantalla,'string');
s=strcat(s,'1')
set(handles.pantalla,'string',s);

% --- Executes on button press in pb3.


function pb3_Callback(hObject, eventdata, handles)
% boton 3
s=get(handles.pantalla,'string');
s=strcat(s,'3')
set(handles.pantalla,'string',s);

Mecánica Computacional II -
2019
GUÍA DE LABORATORIO 03 MECANICA COMPUTACIONAL PAG 4/ 17
II

% --- Executes on button press in pb2.


function pb2_Callback(hObject, eventdata, handles)
% boton 2
s=get(handles.pantalla,'string');
s=strcat(s,'2')
set(handles.pantalla,'string',s);

% --- Executes on button press in pb6.


function pb6_Callback(hObject, eventdata, handles)
% boton 6
s=get(handles.pantalla,'string');
s=strcat(s,'6')
set(handles.pantalla,'string',s);

% --- Executes on button press in pb9.


function pb9_Callback(hObject, eventdata, handles)
% boton 9
s=get(handles.pantalla,'string');
s=strcat(s,'9')
set(handles.pantalla,'string',s);

% --- Executes on button press in pb7.


function pb7_Callback(hObject, eventdata, handles)
% boton 7
s=get(handles.pantalla,'string');
s=strcat(s,'7')
set(handles.pantalla,'string',s);

% --- Executes on button press in pb4.


function pb4_Callback(hObject, eventdata, handles)
% boton 4
s=get(handles.pantalla,'string');
s=strcat(s,'4')
set(handles.pantalla,'string',s);

% --- Executes on button press in pb5.


function pb5_Callback(hObject, eventdata, handles)
% boton 5
s=get(handles.pantalla,'string');
s=strcat(s,'5')
set(handles.pantalla,'string',s);

% --- Executes on button press in pb8.


function pb8_Callback(hObject, eventdata, handles)
% boton 8
s=get(handles.pantalla,'string');
s=strcat(s,'8')
set(handles.pantalla,'string',s);

% --- Executes on button press in pb0.


function pb0_Callback(hObject, eventdata, handles)
% boton 0
s=get(handles.pantalla,'string');
s=strcat(s,'0')
set(handles.pantalla,'string',s);

% --- Executes on button press in pbp.


function pbp_Callback(hObject, eventdata, handles)
Mecánica Computacional II -
2019
GUÍA DE LABORATORIO 03 MECANICA COMPUTACIONAL PAG 5/ 17
% boton . II
s=get(handles.pantalla,'string');
s=strcat(s,'.')
set(handles.pantalla,'string',s);

% --- Executes on button press in pbi.


function pbi_Callback(hObject, eventdata, handles)
% boton =
s=get(handles.pantalla,'string');
s=eval(s)
set(handles.pantalla,'string',s);

% --- Executes on button press in pbr.


function pbr_Callback(hObject, eventdata, handles)
% boton -

s=get(handles.pantalla,'string');
s=strcat(s,'-')
set(handles.pantalla,'string',s);

% --- Executes on button press in pbm.


function pbm_Callback(hObject, eventdata, handles)
% boton *
s=get(handles.pantalla,'string');
s=strcat(s,'*')
set(handles.pantalla,'string',s);

% --- Executes on button press in pbd.


function pbd_Callback(hObject, eventdata, handles)
% boton /
s=get(handles.pantalla,'string');
s=strcat(s,'/')
set(handles.pantalla,'string',s);

% --- Executes on button press in pbs.


function pbs_Callback(hObject, eventdata, handles)
% boton +
s=get(handles.pantalla,'string');
s=strcat(s,'+')
set(handles.pantalla,'string',s);

% --- Executes on button press in pbce.


function pbce_Callback(hObject, eventdata, handles)
% boton cero
s=get(handles.pantalla,'string');
s=('')
set(handles.pantalla,'string',s);

% --- Executes on button press in pbz.


function pbz_Callback(hObject, eventdata, handles)
% boton volver
b=char('')
c=get(handles.pantalla,'string');
set(handles.pantalla,'string',b);
for i=1:length(c)-1
a=c(i);
b=strcat(b,a);
end
set(handles.pantalla,'string',b);
Mecánica Computacional II -
2019
GUÍA DE LABORATORIO 03 MECANICA COMPUTACIONAL PAG 6/ 17
II
% hObject handle to pbrai (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

Salida – Pruebas realizadas

Mecánica Computacional II -
2019
GUÍA DE LABORATORIO 03 MECANICA COMPUTACIONAL PAG 7/ 17
II

6.1 Modifique el GUI graficadoraXY.fig que permita graficar cualquier función, así como
tabular los datos graficados.

Codificación

Mecánica Computacional II -
2019
GUÍA DE LABORATORIO 03 MECANICA COMPUTACIONAL PAG 8/ 17
II

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

% Last Modified by GUIDE v2.5 30-Sep-2019 21:18:57

% Begin initialization code - DO NOT EDIT


gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @Graficadora_LiraSteven_OpeningFcn, ...
'gui_OutputFcn', @Graficadora_LiraSteven_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

Mecánica Computacional II -
2019
GUÍA DE LABORATORIO 03 MECANICA COMPUTACIONAL PAG 9/ 17
II
% --- Executes just before Graficadora_LiraSteven is made visible.
function Graficadora_LiraSteven_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 Graficadora_LiraSteven (see VARARGIN)

% Choose default command line output for Graficadora_LiraSteven


handles.output = hObject;

% Update handles structure


guidata(hObject, handles);

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


% uiwait(handles.figure1);

% --- Outputs from this function are returned to the command line.
function varargout = Graficadora_LiraSteven_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 eTextFun_Callback(hObject, eventdata, handles)


% hObject handle to eTextFun (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 eTextFun as text


% str2double(get(hObject,'String')) returns contents of eTextFun as a double

% --- Executes during object creation, after setting all properties.


function eTextFun_CreateFcn(hObject, eventdata, handles)
% hObject handle to eTextFun (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 eTextLin_Callback(hObject, eventdata, handles)


% hObject handle to eTextLin (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 eTextLin as text


% str2double(get(hObject,'String')) returns contents of eTextLin as a double

% --- Executes during object creation, after setting all properties.


function eTextLin_CreateFcn(hObject, eventdata, handles)
% hObject handle to eTextLin (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB

Mecánica Computacional II -
2019
GUÍA DE LABORATORIO 03 MECANICA COMPUTACIONAL PAG 10/
% handles II
empty - handles not 17
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 eTextInc_Callback(hObject, eventdata, handles)


% hObject handle to eTextInc (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 eTextInc as text


% str2double(get(hObject,'String')) returns contents of eTextInc as a double

% --- Executes during object creation, after setting all properties.


function eTextInc_CreateFcn(hObject, eventdata, handles)
% hObject handle to eTextInc (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 eTextLsu_Callback(hObject, eventdata, handles)


% hObject handle to eTextLsu (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 eTextLsu as text


% str2double(get(hObject,'String')) returns contents of eTextLsu as a double

% --- Executes during object creation, after setting all properties.


function eTextLsu_CreateFcn(hObject, eventdata, handles)
% hObject handle to eTextLsu (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 eTextTgra_Callback(hObject, eventdata, handles)


% hObject handle to eTextTgra (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 eTextTgra as text


% str2double(get(hObject,'String')) returns contents of eTextTgra as a double

Mecánica Computacional II -
2019
GUÍA DE LABORATORIO 03 MECANICA COMPUTACIONAL PAG 11/
II 17
% --- Executes during object creation, after setting all properties.
function eTextTgra_CreateFcn(hObject, eventdata, handles)
% hObject handle to eTextTgra (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 pButtonGra.


function pButtonGra_Callback(hObject, eventdata, handles)
% hObject handle to pButtonGra (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
clc
f = get(handles.eTextFun,'String'); % f <-- eTextFun (como texto)
a = str2num(get(handles.eTextLin,'String')); % a <-- eTextLin (como número);
b = str2num(get(handles.eTextInc,'String')); % a <-- eTextInc (como número);
c = str2num(get(handles.eTextLsu,'String')); % a <-- eTextLsu (como número);
x=a:b:c;
y=eval(f);
plot(x,y,'-.bs','MarkerEdgeColor','k');
xlabel('tiempo');
texto = 'y(x) = ';
texto = strcat(texto,f);
ylabel(texto);
titulo = get(handles.eTextTgra,'String');
title(titulo);
grid
% --- Executes on button press in pButtonLgra.
function pButtonLgra_Callback(hObject, eventdata, handles)
% hObject handle to pButtonLgra (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
cla; % limpia grafica actual
lim = '';
xlabel(lim);
ylabel(lim);
title(lim);

% --- Executes on button press in pButtonLcam.


function pButtonLcam_Callback(hObject, eventdata, handles)
% hObject handle to pButtonLcam (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
lim = '';
set(handles.eTextFun,'String',lim);
set(handles.eTextLin,'String',lim);

% --- Executes on button press in pButtonSal.


function pButtonSal_Callback(hObject, eventdata, handles)
% hObject handle to pButtonSal (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
opc = questdlg('¿Desea salir del programa?','Salir','Si','No','No');
if strcmp(opc,'No')
return;
else
clc, clear all, close all;
end

Mecánica Computacional II -
2019
GUÍA DE LABORATORIO 03 MECANICA COMPUTACIONAL PAG 12/
II 17

Salida – Prueba

III. CUESTIONARIO FINAL.


Para cada una de las preguntas, consigne los pasos seguidos para su solución de
Mecánica Computacional II -
2019
GUÍA DE LABORATORIO 03 MECANICA COMPUTACIONAL PAG 13/
problema con Matlab. II 17

6.1 Modifique el GUI graficadoraXY.fig que permita graficar cualquier función, así como
tabular los datos graficados.
6.2 Modifique el GUI calculadoraXY.fig que permita la selección del modo Estándar y
Científico. Este atento a los requerimientos solicitados por el usuario para el
funcionamiento del GUI.
IV. CONCLUSIONES Y OBSERVACIONES (Emita al menos 4 conclusiones)
 Con todas las funciones que logramos aprender podemos programar desde una calculadora
común y corriente hasta una calculadora científica.
 Que podemos combinar los códigos y poder realizar una graficadora que tenga integrada la
calculadora.
 Podemos concluir que se puede programar cualquier cosa que sea electrónica
 Podemos modificar si queremos una calculadora con más funciones y características sin
necesidad que sea una estándar o científica

Mecánica Computacional II -
2019

También podría gustarte