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

% Last Modified by GUIDE v2.5 26-Feb-2010 12:43:56

% Begin initialization code - DO NOT EDIT_INPUTFILENAME_OUTPUT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @exp2pdf21_OpeningFcn, ...
                   'gui_OutputFcn',  @exp2pdf21_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_INPUTFILENAME_OUTPUT


% --- Executes just before exp2pdf21 is made visible.
function exp2pdf21_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 exp2pdf21 (see VARARGIN)

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

set(hObject,'toolbar','figure');

% Update handles structure
guidata(hObject, handles);

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


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


%---------------------------------------------------------------------
%----------------------------------BUTTONS----------------------
%---------------------------------------------------------------------

%------------Callbacks

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

%input=get(hObject,'String');
%guidata(hObject, handles);

function edit_outputfilename_Callback(hObject, eventdata, handles)

function edit2_binsize_Callback(hObject, eventdata, handles)

function edit3_maximum_Callback(hObject, eventdata, handles)

function edit7_minimum_Callback(hObject, eventdata, handles)


%-----------------CreateFcn

% --- Executes during object creation, after setting all properties.
function edit_inputfilename_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_inputfilename (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_inputfilename 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 during object creation, after setting all properties.
function edit_outputfilename_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

% --- Executes during object creation, after setting all properties.
function edit2_binsize_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

% --- Executes during object creation, after setting all properties.
function edit3_maximum_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

% --- Executes during object creation, after setting all properties.
function edit7_minimum_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function text1_CreateFcn(hObject, eventdata, handles)
function text2_CreateFcn(hObject, eventdata, handles)
function text3_CreateFcn(hObject, eventdata, handles)
function text4_CreateFcn(hObject, eventdata, handles)
function text5_CreateFcn(hObject, eventdata, handles)
function text6_CreateFcn(hObject, eventdata, handles)
function text7_CreateFcn(hObject, eventdata, handles)
function text8_CreateFcn(hObject, eventdata, handles)
function text_log_CreateFcn(hObject, eventdata, handles)
function text9_CreateFcn(hObject, eventdata, handles)

%------PUSH BUTTONS---------

% --- Executes during object creation, after setting all properties.
function pushbutton_inputbrowse_CreateFcn(hObject, eventdata, handles)

% --- Executes on button press in pushbutton4.
function pushbutton_inputbrowse_Callback(hObject, eventdata, handles)
[soubor,cesta]=uigetfile('*.*');
s=strcat(cesta, soubor);
%path(cesta);%set current directory
set(handles.edit_inputfilename,'String',s);
inputE =load(s);
maxE=max(inputE);
minE=min(inputE); %find maximum and minimum in inputfile
pocet=length(inputE)%number of values in a list

%Show text onscreen
set (handles.edit7_minimum,'String', num2str(minE));%show maximum onscreen
set (handles.edit3_maximum,'String', num2str(maxE));%show minimum onscreen
set (handles.listbox_input,'String', inputE);
set (handles.text21_n,'String', num2str(pocet));
%Show text_log
t=strcat('Input file selected: ' ,soubor);
set(handles.text_log,'String', t );

guidata(hObject, handles); %updates the handles


% --- Executes during object creation, after setting all properties.
function pushbutton_outputbrowse_CreateFcn(hObject, eventdata, handles)

% --- Executes on button press in pushbutton_outputbrowse.
function pushbutton_outputbrowse_Callback(hObject, eventdata, handles)
[soubor,cesta]=uiputfile('*.*');
s=strcat(cesta, soubor);
set(handles.edit_outputfilename,'String',s);

%Show text_log
t=strcat('Output file selected: ' , soubor);
set(handles.text_log,'String', t );

guidata(hObject, handles); %updates the handles


function pushbutton_showPDF_CreateFcn(hObject, eventdata, handles)

% --- Executes on button press in pushbutton_showPDF.
function pushbutton_showPDF_Callback(hObject, eventdata, handles)

E =load(get(handles.edit_inputfilename,'String'));
binsize=str2double(get(handles.edit2_binsize,'String'));
minbin=str2double(get(handles.edit7_minimum,'String'));
maxbin=str2double(get(handles.edit3_maximum,'String'));
kategorie=minbin:binsize:maxbin;
n=length(E);%number of values in a list
hi=histc(E,kategorie); %histogram by categories
Epdf=hi/n; %probability density function (property must be divided by the number of values and binsize)
Epdf=Epdf/binsize;
SumEpdf=sum(Epdf);
SUM=SumEpdf  .* binsize;
axes(handles.graf_PDF); %plots the x and y data
bar(kategorie,Epdf);
%adds a title, x-axis description, and y-axis description
%title('PDF');
xlabel('Property');
ylabel('Frequency density');

%Write output to file
f=fopen( get(handles.edit_outputfilename,'String'), 'wt');
%f=fopen('output1.txt','wt');
A(:,1)= kategorie' ; %fill the first column of A by vector of categories
A(:,2)=  Epdf; %fill the secondf column of A by PDF
fprintf(f, '%e %e\n', A'); %print A to outputfile (A is transposed for printing)
fclose(f);

%Show text onscreen
set(handles.listbox_kategorie,'String', A(:,1));
set(handles.listbox_PDF,'String', A(:,2));
set(handles.text23_sum,'String', SumEpdf);
set(handles.text26_sxb,'String', SUM);
%Show text_log
t=strcat('PDF written to: ' , get(handles.edit_outputfilename, 'String'));
set(handles.text_log,'String', t );

guidata(hObject, handles); %updates the handles


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

% Hint: place code in OpeningFcn to populate graf_PDF


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


% --------------------------------------------------------------------
function uipanel2_SelectionChangeFcn(hObject, eventdata, handles)
% hObject    handle to uipanel2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)



% --- Executes on key press over edit2_binsize with no controls selected.
function edit2_binsize_KeyPressFcn(hObject, eventdata, handles)
% hObject    handle to edit2_binsize (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --- Executes on key press over edit_inputfilename with no controls selected.
function edit_inputfilename_KeyPressFcn(hObject, eventdata, handles)
% hObject    handle to edit_inputfilename (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --- Executes on key press over edit_outputfilename with no controls selected.
function edit_outputfilename_KeyPressFcn(hObject, eventdata, handles)
% hObject    handle to edit_outputfilename (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)



%--------LISTBOXES

% --- Executes on selection change in listbox_kategorie.
function listbox_kategorie_Callback(hObject, eventdata, handles)

% --- Executes during object creation, after setting all properties.
function listbox_kategorie_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on selection change in listbox_PDF.
function listbox_PDF_Callback(hObject, eventdata, handles)

% --- Executes during object creation, after setting all properties.
function listbox_PDF_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function listbox_input_Callback(hObject, eventdata, handles)


function listbox_input_CreateFcn(hObject, eventdata, handles)

% Hint: listbox 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 figure1_ResizeFcn(hObject, eventdata, handles)


