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

% Last Modified by GUIDE v2.5 09-May-2011 10:57:00

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

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

% Update handles structure
guidata(hObject, handles);

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

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

%Datei einlesen:

%Windows-Explorer öffenen!
[xlsfile,path2xls] = uigetfile ('*.xls', 'Bitte wählen');
%Einlesen der Excel-Tabelle!
rawdata1 = xlsread(fullfile(path2xls,xlsfile)); 
%Definition als Zeilenvektor
m1 = [rawdata1(:,1);rawdata1(:,2)];
%Bestimmen der Zeilenanzahl
z1 = length(m1)/2;
%Definition der m x n Matrix
m1 = reshape(m1,z1,2);
%Definition als Zeilenvektor
m2 = [rawdata1(:,1);rawdata1(:,3)];
%Bestimmen der Zeilenanzahl
z2 = length(m2)/2;
%Definition der m x n Matrix
m2 = reshape(m2,z2,2);

%Definition der Trendlinie

%Definition der X-Achse
m1_x = m1(:,2); 
%Definition der Y-Achse
m1_y = m1(:,1);             
%m und n für Geradengleichung
geradenwerte1 = polyfit (log(m1_x), log(m1_y), 2);
%x-Intervall für Geradengleichung
m1_xi = log(0:500);   
%Werte der Geradengleichung
gerade1 = polyval(geradenwerte1, m1_xi); 

%Definition der X-Achse
m2_x = m2(:,2); 
%Definition der Y-Achse
m2_y = m2(:,1);             
%m und n für Geradengleichung
geradenwerte1 = polyfit (log(m2_x), log(m2_y), 2);
%x-Intervall für Geradengleichung
m2_xi = log(0:500);   
%Werte der Geradengleichung
gerade2 = polyval(geradenwerte1, m2_xi);  

%Übergabe der Daten

handles.m1_x = m1_x;
handles.m2_x = m2_x;
handles.m1_y = m1_y;
handles.m2_y = m2_y;
handles.m1_xi = m1_xi;
handles.m2_xi = m2_xi;
handles.gerade1 = gerade1;
handles.gerade2 = gerade2;

guidata(hObject, handles);

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

% Hint: get(hObject,'Value') returns toggle state of checkbox_I

auswahl = handles.auswahl;

if get (hObject, 'value') ==1
    if auswahl ==1
        set(handles.punkte1, 'visible', 'on');
    elseif auswahl ==2
        set(handles.linie1, 'visible', 'on');
    end
elseif get(hObject, 'Value') ==0
    if auswahl == 1
        set(handles.punkte1, 'visible', 'off');
    elseif auswahl == 2
        set(handles.linie1, 'visible', 'off');
    end
end

guidata(hObject, handles);

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

% Hint: get(hObject,'Value') returns toggle state of checkbox_II

auswahl = handles.auswahl;

if get (hObject, 'value') ==1
    if auswahl == 1
        set(handles.punkte2, 'visible', 'on');
    elseif auswahl == 2
        set(handles.linie2, 'visible', 'on');
    end
elseif get(hObject, 'Value') ==0
    if auswahl == 1
        set(handles.punkte2, 'visible', 'off');
    elseif auswahl == 2
        set(handles.linie2, 'visible', 'off');
    end
end

guidata(hObject, handles);

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

% Hints: contents = cellstr(get(hObject,'String')) returns popupmenu1 contents as cell array
%        contents{get(hObject,'Value')} returns selected item from popupmenu1

%Übernahme der Daten

m1_x = handles.m1_x;
m2_x = handles.m2_x;
m1_y = handles.m1_y;
m2_y = handles.m2_y;
m1_xi = handles.m1_xi;
m2_xi = handles.m2_xi;
gerade1 = handles.gerade1;
gerade2 = handles.gerade2;

%Definition des popup-menus

val = get (hObject, 'Value');

if val == 2
    auswahl = 1;
    handles.auswahl = auswahl;
    %Dartsetllung der Punkte
    handles.punkte1 = loglog(m1_x, m1_y, 'b*');
    %zunächst nicht sichtabr machen
    set(handles.punkte1, 'visible', 'off');
    hold on;
    %Dartsetllung der Punkte
    handles.punkte2 = loglog(m2_x, m2_y, 'r*');
    %zunächst nicht sichtabr machen
    set(handles.punkte2, 'visible', 'off');
    hold off;
elseif val ==3
    auswahl = 2;
    handles.auswahl = auswahl;
    %Darstellung der Geraden
    handles.linie1 = loglog(exp(m1_xi), exp(gerade1), 'b');
    %zunächst nicht sichtabr machen
    set(handles.linie1, 'visible', 'off');
    hold on;
    %Darstellung der Geraden
    handles.linie2 = loglog(exp(m2_xi), exp(gerade2), 'r');
    %zunächst nicht sichtabr machen
    set(handles.linie2, 'visible', 'off');
    hold off;    
end

guidata(hObject, handles);

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