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

% Last Modified by GUIDE v2.5 13-Apr-2011 09:38:39

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



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

% Update handles structure
guidata(hObject, handles);


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


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



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


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



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


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


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


% --- Executes during object creation, after setting all properties.
function yKmax_CreateFcn(hObject, eventdata, handles)
% hObject    handle to yKmax (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 do.
function do_Callback(hObject, eventdata, handles)
% hObject    handle to do (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


addpath Z:\Masterarbeit\Dokumente
Stationen=xlsread('Alle_DE-Nullung','MATLAB');
x=Stationen(:,1);
y=Stationen(:,2);
hold on
voronoi(x,y)

xKmin=get(handles.xKmin, 'String')
xKmax=get(handles.xKmax, 'String')
yKmax=get(handles.yKmax, 'String')
yKmin=get(handles.yKmin, 'String')

for i=1:length(Stationen) 
      if Stationen(i,1)<=xKmax  %Wenn iter Wert der ersten Spalte kleiner Grenze
          if Stationen(i,1)>=xKmin %Wenn iter Wert der ersten Spalte größer Grenze
            auswx(z1,:)=Stationen(i,:);  %setze Variable = Wert der zeile
            z1=z1+1;            
          end
      end
end


for i=1:length(auswx)
    for z2=1:length(auswx)
   if auswx(i,2)<=yKmax
       if auswx(i,2)>=yKmin
         ausw(z2,:)=auswx(i,:);
        end
    end
    end
end
     
xsel=ausw(:,1);          %Hole x-Koord der ausgewählten Stationen
ysel=ausw(:,2);          %Hole y-Koord der ausgewählten Stationen
voronoi(xsel,ysel);     %Erstelle Voronoi Diagramm der ausgewählten Stationen
hold on
[v,c]=voronoin(ausw);    %Beginne mit der Einfärbung der ausgewählten
for i=1:length(c)       %Zellen in einer bestimmten Farbe
patch(v(c{i},1),v(c{i},2),'c')  %hier: Cyan
axis([-4000,4000,-8000,0])
end
hold off
