function varargout = Ejercicio4(varargin)
%EJERCICIO4 M-file for Ejercicio4.fig
%      EJERCICIO4, by itself, creates a new EJERCICIO4 or raises the existing
%      singleton*.
%
%      H = EJERCICIO4 returns the handle to a new EJERCICIO4 or the handle to
%      the existing singleton*.
%
%      EJERCICIO4('Property','Value',...) creates a new EJERCICIO4 using the
%      given property value pairs. Unrecognized properties are passed via
%      varargin to Ejercicio4_OpeningFcn.  This calling syntax produces a
%      warning when there is an existing singleton*.
%
%      EJERCICIO4('CALLBACK') and EJERCICIO4('CALLBACK',hObject,...) call the
%      local function named CALLBACK in EJERCICIO4.M with the given input
%      arguments.
%
%      *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 Ejercicio4

% Last Modified by GUIDE v2.5 11-Jan-2019 20:42:31

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @Ejercicio4_OpeningFcn, ...
                   'gui_OutputFcn',  @Ejercicio4_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 Ejercicio4 is made visible.
function Ejercicio4_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   unrecognized PropertyName/PropertyValue pairs from the
%            command line (see VARARGIN)

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

% Update handles structure
guidata(hObject, handles);

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


% --- Outputs from this function are returned to the command line.
function varargout = Ejercicio4_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 slider movement.
function vano_slider_Callback(hObject, eventdata, handles)
% hObject    handle to vano_slider (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% valor=get(hObject,'Value') %returns position of slider
% minimo=get(hObject,'Min');
% maximo=get(hObject,'Max'); %to determine range of slider


% --- Executes during object creation, after setting all properties.
function vano_slider_CreateFcn(hObject, eventdata, handles)
% hObject    handle to vano_slider (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor',[.9 .9 .9]);
end



function vano_tx1_Callback(hObject, eventdata, handles)
vano2 = str2num(get(hObject,'String'));
%Nada introducido: cero asignado
if (isempty(input))
     set(hObject,'String','0')
end



% --- Executes during object creation, after setting all properties.
function vano_tx1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to vano_tx1 (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 tension_tx2_Callback(hObject, eventdata, handles)
tension = str2num(get(hObject,'String'));
%Nada escrito: 0 asignado
if (isempty(input))
     set(hObject,'String','0')
end



% --- Executes during object creation, after setting all properties.
function tension_tx2_CreateFcn(hObject, eventdata, handles)
% hObject    handle to tension_tx2 (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 peso_tx3_Callback(hObject, eventdata, handles)
peso = str2num(get(hObject,'String'));
%Nada introducido: cero asignado
if (isempty(input))
     set(hObject,'String','0')
end


% --- Executes during object creation, after setting all properties.
function peso_tx3_CreateFcn(hObject, eventdata, handles)
% hObject    handle to peso_tx3 (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 hmin_tx4_Callback(hObject, eventdata, handles)
hmin = str2num(get(hObject,'String'));
%Nada introducido: cero asignado
if (isempty(input))
     set(hObject,'String','0')
end


% --- Executes during object creation, after setting all properties.
function hmin_tx4_CreateFcn(hObject, eventdata, handles)
% hObject    handle to hmin_tx4 (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 calc_bt.
function calc_bt_Callback(hObject, eventdata, handles)
    vano1 = get(handles.vano_tx1,'String');
    vano2 = get(handles.vano_slider,'String');
    tension = get(handles.tension_tx2,'String');
    peso = get(handles.peso_tx3,'String');

    %Cálculo de la flecha:
    h1=str2double(tension)/str2double(peso)*(cosh(str2double(peso)*str2double(vano1)/(2*str2double(tension)))-1);
    h2=str2double(tension)/str2double(peso)*(cosh(str2double(peso)*str2double(vano2)/(2*str2double(tension)))-1);
    H1=num2str(h1); H2=num2str(h2);

    %Cálculo de la longitud:
    long1=str2double(tension)/str2double(peso)*(sinh(str2double(peso)*str2double(vano1)/(2*str2double(tension))));
    long2=str2double(tension)/str2double(peso)*(sinh(str2double(peso)*str2double(vano2)/(2*str2double(tension))));
    L1=num2str(long1) ;L2=num2str(long2)  ;
    %A continuación, se muestra el resultado de los cálculos:
    set(handles.result_tx5,'string',[' El valor de la flecha es:',H1,'  ','El valor de la longitud es:',L1,'  ']) ; guidata(hObject, handles);


% --- Executes on button press in graf_bt.
function graf_bt_Callback(hObject, eventdata, handles)
% hObject    handle to graf_bt (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
    vano1 = str2double(get(handles.vano_tx1,'String'));
    vano2 = str2double(get(handles.vano_slider,'String'));
    tension = str2double(get(handles.tension_tx2,'String'));
    peso = str2double(get(handles.peso_tx3,'String'));
    hmin = str2double(get(handles.hmin_tx4,'String'));
    %cálculo de la altura:
    h1=tension/peso*(cosh(peso*vano1/(2*tension))-1);
%Graficado de la catenaria en los axes:
xd=linspace(-350,750);y=tension/peso*(cosh(peso*(2*xd-vano1)/(2*tension))-cosh(peso*vano1/(2*tension)))+hmin+h1;
plot(xd,y);grid on;




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


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