function varargout = Ejercicio4(varargin)
% EJERCICIO4 MATLAB code 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('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in EJERCICIO4.M with the given input arguments.
%
%      EJERCICIO4('Property','Value',...) creates a new EJERCICIO4 or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before Ejercicio4_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to Ejercicio4_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 Ejercicio4

% Last Modified by GUIDE v2.5 15-Jan-2019 11:10:35

% 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


% --- 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 slider2_Callback(hObject, eventdata, handles)
% hObject    handle to slider2 (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,'Value') returns position of slider
%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider
% obtiene valor del slider
slidev = get(handles.slider2,'Value');
% asigna valor del slider en edit text
set(handles.Valorbarra,'String',num2str(slidev));
% actualiza la estructura handle
guidata(hObject,handles);

% --- Executes during object creation, after setting all properties.
function slider2_CreateFcn(hObject, eventdata, handles)
% hObject    handle to slider2 (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 barra_Callback(hObject, eventdata, handles)
% hObject    handle to Valorbarra (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 Valorbarra as text
%        str2double(get(hObject,'String')) returns contents of Valorbarra as a double
slidev = get(handles.Valorbarra,'String');
% convierte string a numero
slidevn = str2num(slidev);
% comprueba si no es un numero o si esta fuera de rango 50-1050
if (isempty(slidev) || slidevn <50 || slidevn >1050)
    set(handles.slider2,'Value',50);
    set(handles.Valorbarra,'String','50');
else
    set(handles.slider2,'Value',slidevn);
end

% --- Executes during object creation, after setting all properties.
function barra_CreateFcn(hObject, eventdata, handles)
% hObject    handle to Valorbarra (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_Callback(hObject, eventdata, handles)
% hObject    handle to Tension (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 Tension as text
%        str2double(get(hObject,'String')) returns contents of Tension as a double


% --- Executes during object creation, after setting all properties.
function tension_CreateFcn(hObject, eventdata, handles)
% hObject    handle to Tension (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_Callback(hObject, eventdata, handles)
% hObject    handle to Peso (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 Peso as text
%        str2double(get(hObject,'String')) returns contents of Peso as a double


% --- Executes during object creation, after setting all properties.
function peso_CreateFcn(hObject, eventdata, handles)
% hObject    handle to Peso (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_Callback(hObject, eventdata, handles)
% hObject    handle to Hmin (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 Hmin as text
%        str2double(get(hObject,'String')) returns contents of Hmin as a double


% --- Executes during object creation, after setting all properties.
function hmin_CreateFcn(hObject, eventdata, handles)
% hObject    handle to Hmin (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 Calcula.
function calcula_Callback(hObject, eventdata, handles)
% hObject    handle to Calcula (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)
f = get(handles.barra,'String');
b = get(handles.tension,'String');
c = get(handles.peso,'String');
d = get(handles.hmin,'String');
a = str2num(f);
T = str2num(b);
P= str2num(c);
Hmi = str2num(d);
h=(T/P)*(cosh((P*a)/(2*T))-1);
L=(T/P)*sinh((P*a)/(2*T));
x=linspace(0,a);
y=(T/P)*(cosh((P/(2*T))*(2*x-a))-cosh((P*a)/(2*T)))+h+Hmi;
axis on
plot(x,y);
title('Axes 1');
guidata(hObject,handles);
Undefined function 'Ejercicio4_OpeningFcn' for input arguments of type 'matlab.ui.Figure'.

Error in gui_mainfcn (line 220)
    feval(gui_State.gui_OpeningFcn, gui_hFigure, [], guidata(gui_hFigure), varargin{:});

Error in Ejercicio4 (line 42)
    gui_mainfcn(gui_State, varargin{:});