Vous êtes sur la page 1sur 11

function varargout = untitled(varargin)

% UNTITLED MATLAB code 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 28-Feb-2019 23:01:34

% 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
end

% --- 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);
end

% --- 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 l ine output from handles structure


varargout{1} = handles.output;

end

function edit1_Callback(hObject, eventdata, handles)


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


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

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


function edit1_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit1 (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

end

function edit2_Callback(hObject, eventdata, handles)


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


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

end
% --- Executes during object creation, after setting all properties.
function edit2_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit2 (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
end

function edit3_Callback(hObject, eventdata, handles)


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


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

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


function edit3_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit3 (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

end
% --- 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)
set(handles.edit8,'string',0);
cla;
cla (handles.axes2, 'reset' );
cla (handles.axes3, 'reset' );
altura=str2double(get(handles.edit2,'String'));
febb=altura;
masa =(80-str2double(get(handles.edit1,'String')))*0.01+0.01;
cla;
v=str2double(get(handles.edit3,'String'));
cla;
set(handles.edit7,'string',(altura/2)+1);

z=0:pi/100:2*pi;
x=(febb+2)/2+cos(z);
y=febb+sin(z);
axes(handles.axes1);
plot(x,y+1);
axis([-2 febb+5 -2 febb+5])
hold on;
pause(0.001)

if (masa~=0.81)

main(altura,masa,v);

end

function main(altura,masa,v)
A=["Masa" "Altura inicial" "Vo";masa altura v];
xlswrite('untitled.xlsx',A,'Hoja1','A1');
feb=altura;
dt=1/50;
db=masa*1500;
tf = sqrt(altura)*db;
g=-9.81;

times=dt:dt:tf;
time=0:1/(length(times)):1;
heights= zeros;

q=zeros(1,length(times));
p=zeros(1,length(times));
r=zeros(1,length(times));

for idx=1:length(times)

val=str2double(get(handles.edit8,'String'));
newh=altura +(v+g*dt/2)*dt;
posx=str2double(get(handles.edit7,'String'));
lv=v;
v=v+g*dt;
q(idx)=abs(newh);
p(idx)=abs(v);
r(idx)=posx;
set(handles.edit6,'string',times(idx));
if val==1
if newh < 0
k=0;
newh=0;
v=-v*sqrt(masa);
else
k=1;
end
set(handles.edit7,'string',((feb+1.5*time(idx))/2)+1);
heights(idx)=newh;
altura=newh;
if(k==0)
oval(0,heights(idx),feb+1.5*time(idx));
else
circle(0,heights(idx),feb+1.5*time(idx));
end
if(lv>=0 && v<=0 && altura<0.2)
for i=0:0.013:0.1
circle(0,0.1-i,feb+1.5*time(idx));
set(handles.edit8,'string',4);
end
break
end
end
if val==0
if newh < 0
k=0;
newh=0;
v=-v*sqrt(masa);
else
k=1;
end
heights(idx)=newh;
altura=newh;
if(k==0)
oval(0,heights(idx),feb);
else
circle(0,heights(idx),feb);
end

if(lv>=0 && v<=0 && altura<0.2)


for i=0:0.013:0.1
circle(0,0.1-i,feb);
set(handles.edit8,'string',4);
end
break
end
end
if val==2
if newh < 0
k=0;
newh=0;
v=-v*sqrt(masa);
else
k=1;
end
heights(idx)=newh;
altura=newh;
set(handles.edit7,'string',((feb-1.5*time(idx))/2)+1);
if(k==0)
oval(0,heights(idx),feb-1.5*time(idx));
else
circle(0,heights(idx),feb-1.5*time(idx));
end

if(lv>=0 && v<=0 && altura<0.2)


for i=0:0.013:0.1
circle(0,0.1-i,feb-1.5*time(idx));
set(handles.edit8,'string',4);
end
break
end
end

h (idx,times,p,q,r);
end

end
function oval (x,y,c)
cla;
curve = animatedline('LineWidth',1,'Color','k', 'Parent', handles.axes1);
z=0:pi/100:2*pi;
x=x+1.2*cos(z);
y=y+sin(z);
addpoints(curve,x+(c/2)+1,y+1);

drawnow;

end
function circle(x,y,c)
cla;
curve = animatedline('LineWidth',1,'Color','k', 'Parent', handles.axes1);
z=0:pi/100:2*pi;
x=x+cos(z);
y=y+sin(z);
addpoints(curve,x+(c/2)+1,y+1);

drawnow;

end
function h (idx,times,p,q,r)
clc;

curve = animatedline('LineWidth',1,'Color','r', 'Parent', handles.axes2);


addpoints(curve,times(1:idx),q(1:idx));
drawnow;
set(handles.edit4,'string',q(idx));

curve = animatedline('LineWidth',1,'Color','b', 'Parent', handles.axes2);


addpoints(curve,times(1:idx),p(1:idx));
drawnow;
set(handles.edit5,'string',p(idx));

curve = animatedline('LineWidth',1,'Color','k', 'Parent', handles.axes3);


addpoints(curve,times(1:idx),r(1:idx));
drawnow;

xlswrite('untitled.xlsx',p(1:idx),'Hoja1','A3');
xlswrite('untitled.xlsx',q(1:idx),'Hoja1','A4');
xlswrite('untitled.xlsx',r(1:idx),'Hoja1','A5');

end
end

function edit4_Callback(hObject, eventdata, handles)


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


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

end
% --- Executes during object creation, after setting all properties.
function edit4_CreateFcn(hObject, ~, handles)
% hObject handle to edit4 (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
end

function edit5_Callback(hObject, eventdata, handles)


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


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

end
% --- Executes during object creation, after setting all properties.
function edit5_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit5 (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
end

function edit6_Callback(hObject, eventdata, handles)


% hObject handle to edit6 (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 edit6 as text
% str2double(get(hObject,'String')) returns contents of edit6 as a double

end
% --- Executes during object creation, after setting all properties.
function edit6_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit6 (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
end

% --- 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)
h=str2double(get(handles.edit2,'String'));
val=str2double(get(handles.edit8,'String'));
if val~=4
set(handles.edit8,'string',1);
iman(0,0,h+5);
end
function circle(x,y,c)
cla;
curve = animatedline('LineWidth',1,'Color','k', 'Parent', handles.axes1);
z=0:pi/100:2*pi;
x=x+cos(z);
y=y+sin(z);
addpoints(curve,x+(c/2)+1,y+1);

drawnow;
end
function iman(x,y,c)
cla;
curve = animatedline('LineWidth',1,'Color','r', 'Parent', handles.axes1);
z=-pi/2-1:pi/100:pi/2;
x=x+cos(z);
y=y+sin(z);
addpoints(curve,x+(c/2)+1,y+1);

drawnow;
end

posicionx=str2double(get(handles.edit7,'String'));
times=0:1/50:1;

val=str2double(get(handles.edit8,'String'));
if val==4
for idx=1:length(times)
iman(0,0,(((posicionx+2-1)+times(idx))*2));
circle(0,0,((posicionx-1)+times(idx))*2);

end
set(handles.edit7,'string',(posicionx)+1);
end

end

% --- Executes on button press in pushbutton3.


function pushbutton3_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
h=str2double(get(handles.edit2,'String'));
val=str2double(get(handles.edit8,'String'));
if val~=4
set(handles.edit8,'string',2);
iman(0,0,(h-5));
end

function circle(x,y,c)
cla;
curve = animatedline('LineWidth',1,'Color','k', 'Parent', handles.axes1);
z=0:pi/100:2*pi;
x=x+cos(z);
y=y+sin(z);
addpoints(curve,x+(c/2)+1,y+1);

drawnow;
end
function iman(x,y,c)
cla;
curve = animatedline('LineWidth',1,'Color','r', 'Parent', handles.axes1);
z=pi-1:pi/100:2*pi-1;
x=x+cos(z);
y=y+sin(z);
addpoints(curve,x+(c/2)+1,y+1);

drawnow;
end

posicionx=str2double(get(handles.edit7,'String'));

times=0:1/50:1;
val=str2double(get(handles.edit8,'String'));
if val==4
for idx=1:length(times)
iman(0,0,((posicionx-2-1)-times(idx))*2);
circle(0,0,((posicionx-1)-times(idx))*2);
end
set(handles.edit7,'string',(posicionx)-1);
end

end
function edit7_Callback(hObject, eventdata, handles)
% hObject handle to edit7 (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 edit7 as text


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

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


function edit7_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit7 (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
end

function edit8_Callback(hObject, eventdata, handles)


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


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

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


function edit8_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit8 (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
end

function edit9_Callback(hObject, eventdata, handles)


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


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

end
% --- Executes during object creation, after setting all properties.
function edit9_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit9 (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
end

function edit10_Callback(hObject, eventdata, handles)


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


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

end
% --- Executes during object creation, after setting all properties.
function edit10_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit10 (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
end

Vous aimerez peut-être aussi