function varargout = datos_filtrado(varargin)
% DATOS_FILTRADO M-file for datos_filtrado.fig
%      DATOS_FILTRADO, by itself, creates a new DATOS_FILTRADO or raises the existing
%      singleton*.
%
%      H = DATOS_FILTRADO returns the handle to a new DATOS_FILTRADO or the handle to
%      the existing singleton*.
%
%      DATOS_FILTRADO('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in DATOS_FILTRADO.M with the given input arguments.
%
%      DATOS_FILTRADO('Property','Value',...) creates a new DATOS_FILTRADO or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before datos_filtrado_OpeningFunction gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to datos_filtrado_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
% Copyright 2002-2003 The MathWorks, Inc.
% Edit the above text to modify the response to help datos_filtrado
% Last Modified by GUIDE v2.5 06-Nov-2005 18:48:27

%DEFINICIÓN DE LA FUNCIÓN
% Función que solicita al usuario que introduzca el tiempo de filtrado ,
%es decir, el número de muestras que usa para realizar el filtrado
%y el porcentaje de desviación que considera aceptable en el filtrado.
%NOTA: si el porcentaje y el tiempo de filtrado es '0', no se realizará
%ningún filtrado a los datos_filtrado

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @datos_filtrado_OpeningFcn, ...
                   'gui_OutputFcn',  @datos_filtrado_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 datos_filtrado is made visible.
function datos_filtrado_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 datos_filtrado (see VARARGIN)

tfiltrado  = 0;             %tiempo que se usa para filtrar
porcentaje = 0;             %porcentaje que se considera aceptable para filtrar
flagaceptar  = 0;           %0 no aceptado y 1 aceptado

handles.tfiltrado   = tfiltrado;
handles.porcentaje  = porcentaje;
handles.flagaceptar = flagaceptar;

% Update handles structure
guidata(hObject, handles);

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


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

%Almacen de las variables de salida
try
    varargout{1} = handles.tfiltrado;
    varargout{2} = handles.porcentaje;
    varargout{3} = handles.flagaceptar;
catch
    varargout{1} = [];
    varargout{2} = [];
    varargout{3} = [];

end

closereq



% --- Executes on selection change in tfiltrado_popup.
function tfiltrado_popup_Callback(hObject, eventdata, handles)
% hObject    handle to tfiltrado_popup (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

%Selección del tiempo que se va a usar para realizar el filtrado

tfiltradov=get(hObject,'Value');
tfiltrados=get(hObject,'String');
tfiltrado=str2double(tfiltrados(tfiltradov));
handles.tfiltrado = tfiltrado;
guidata(hObject,handles);


% --- Executes during object creation, after setting all properties.
function tfiltrado_popup_CreateFcn(hObject, eventdata, handles)
% hObject    handle to tfiltrado_popup (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end



% --- Executes on selection change in porcentaje_popup.
function porcentaje_popup_Callback(hObject, eventdata, handles)
% hObject    handle to porcentaje_popup (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

%Selección del porcentaje de desviación permitido para el filtrado
%si el porcentaje es 0, no se realiza ningún filtrado

porcentajev=get(hObject,'Value');
porcentajes=get(hObject,'String');
porcentaje=str2double(porcentajes(porcentajev));
handles.porcentaje = porcentaje;

guidata(hObject,handles);


% --- Executes during object creation, after setting all properties.
function porcentaje_popup_CreateFcn(hObject, eventdata, handles)
% hObject    handle to porcentaje_popup (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end



% --- Executes on button press in aceptar_push.
function aceptar_push_Callback(hObject, eventdata, handles)
% hObject    handle to aceptar_push (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

%Se muestran todos los dato capturados previamente en la pantalla principal
tfiltrado = 0;
porcentaje= 0;

handles.flagaceptar=1;
guidata(hObject,handles);

%obtenemos los valores que queremos almacenar en la pantalla principal
%leemos estas variables para que quede contemplado el caso de que se desee
%no realizar ningún filtrado
porcentajev=get(handles.porcentaje_popup,'Value');
porcentajes=get(handles.porcentaje_popup,'String');
porcentaje=str2double(porcentajes(porcentajev));

tfiltradov=get(handles.tfiltrado_popup,'Value');
tfiltrados=get(handles.tfiltrado_popup,'String');
tfiltrado=str2double(tfiltrados(tfiltradov));

handles.porcentaje=porcentaje;
handles.tfiltrado=tfiltrado;
guidata(hObject,handles)
uiresume;



% --- Executes on button press in deshacer_push.
function deshacer_push_Callback(hObject, eventdata, handles)
% hObject    handle to deshacer_push (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

%Al pulsar dehacer, se almacenan todos los valores por defecto que se han
%establecido al comienzo de esta pantalla y solicita al usuario que vuelva
%a introducir todos los datos_filtrado

handles.flagaceptar = 0;
handles.tfiltrado   = 0;
handles.porcentaje  = 0;
handles.flagaceptar = 0;

set(handles.tfiltrado_popup,'Value',1);
set(handles.porcentaje_popup,'Value',1);
warndlg('AVISO:Debe volver a seleccionar todos los datos del Filtrado','AVISO');

guidata(hObject,handles);



% --- Executes on button press in cancelar_push.
function cancelar_push_Callback(hObject, eventdata, handles)
% hObject    handle to cancelar_push (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

%No se almacenan los datos_filtrado y se cierra la ventana
handles.flagaceptar=0;
guidata(hObject,handles);
uiresume



% --- Executes on button press in ayuda_push.
function ayuda_push_Callback(hObject, eventdata, handles)
% hObject    handle to ayuda_push (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

h1=ayuda_datos_filtrado;
waitfor(h1);

