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

% Last Modified by GUIDE v2.5 27-Aug-2015 11:16:03

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @test_OpeningFcn, ...
                   'gui_OutputFcn',  @test_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 is made visible.
function test_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 (see VARARGIN)
set(handles.ersteKurve,'String','1');
set(handles.zweiteKurve,'String','1');
% Choose default command line output for test
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

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


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



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


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

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


function ersteKurve_Callback(hObject, eventdata, handles)
% hObject    handle to ersteKurve (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 ersteKurve as text
%        str2double(get(hObject,'String')) returns contents of ersteKurve as a double
zc=str2double(get(handles.ersteKurve,'String')); 
            if isempty(zc) || zc < 0 || zc ~= floor(zc)  %prüfen ob eingegebene Variable ein Integer ist
                a=round(zc);  %wenn kein Integer: runden
                set(handles.ersteKurve,'String',a);
            end  
         
 
handles = plotten_oben(hObject,handles);

% Die handles-struktur aktualisieren
guidata(hObject, handles);

% --- Executes during object creation, after setting all properties.
function ersteKurve_CreateFcn(hObject, eventdata, handles)
% hObject    handle to ersteKurve (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 ersteKurve_down.
function ersteKurve_down_Callback(hObject, eventdata, handles)
% hObject    handle to ersteKurve_down (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
%  zc=(get(handles.ersteKurve,'String'));
 zc=str2double(get(handles.ersteKurve,'String'));  
if (zc>1)
    zc=zc-1;
    set(handles.ersteKurve,'String',zc);
end
handles = plotten_oben(hObject,handles);
   
% Die handles-struktur aktualisieren
guidata(hObject, handles);

% --- Executes on button press in ersteKurve_up.
function ersteKurve_up_Callback(hObject, eventdata, handles)
% hObject    handle to ersteKurve_up (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA) 
 zc=str2double(get(handles.ersteKurve,'String')); 
if zc<2
    zc=zc+1;
    set(handles.ersteKurve,'String',zc);
end
    
handles = plotten_oben(hObject,handles);
   
% Die handles-struktur aktualisieren
guidata(hObject, handles);



% --- Executes on button press in Start.
function pushbutton6_Callback(hObject, eventdata, handles)
% hObject    handle to Start (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
  handles = plotten_oben(hObject,handles);  
  handles = plotten_unten(hObject,handles);
  % Die handles-struktur aktualisieren
 guidata(hObject, handles);
    
    
function handles = plotten_oben(hObject,handles)
t = [0:0.1:2*pi];
zc1=  (get(handles.ersteKurve,'String'));   %Bedienfeld 1 
% cla(handles.axes1); % Löscht (falls vorhanden) alle Grafiken im axes1
if isfield(handles,'oben')
    set(handles.ersteKurve, 'XData', [], 'YData', []);
end

switch zc1
    
    case '1'
        B = sin(t);
        
        
    case '2'
        B = sin(2*t);
end

B = B+0.4;

axes(handles.axes1);


if isfield(handles,'Hilf1')
    set(handles.Hilf1, 'XData', [], 'YData', []);
    set(handles.Hilf2, 'XData', [], 'YData', []);
end
 
   handles.Hilf1=line([t(1),t(end)],[0.4,0.4],'LineStyle',':','Color','red');
   handles.Hilf2=line([t(1),t(end)],[1.4,1.4],'LineStyle',':','Color','red'); 
  

    % axes(handles.axes1); lieber weiter ersteKurve schon setzen
    
    
    hold on
    handles.ersteKurve = stairs(t,B,'b'); 
    hold off
    
    ymin = -1.8;
    ymax = +1.8; %Maximum y-Achse
    xmin=min(t);
    xmax=max(t); %Maximum x-Achse
    set(gca,'xlim',[xmin,xmax],'ylim',[ymin, ymax],'YTick',[]); %y-Achse ausblenden
    
   % Die handles-struktur aktualisieren
guidata(hObject, handles); 




%---------------------------------------------------------------------
function handles = plotten_unten(hObject,handles)
zc2=  (get(handles.zweiteKurve,'String'));   %Bedienfeld 2
t = [0:0.1:2*pi];

if isfield(handles,'unten');
      set(handles.zweiteKurve, 'XData', [], 'YData', []);
end

switch zc2
    case '1'            %Stromkurve
        B = sin(t);
        
        
    case '2'
        B = sin(2*t);
end

B = B-1.4;

axes(handles.axes1);


if isfield(handles,'Hilf3')
    set(handles.Hilf3, 'XData', [], 'YData', []);
    set(handles.Hilf4, 'XData', [], 'YData', []);
    drawnow
end

   handles.Hilf3=line([t(1),t(end)],[-1.4,-1.4],'LineStyle',':','Color','red');
   handles.Hilf4=line([t(1),t(end)],[-0.4,-0.4],'LineStyle',':','Color','red');


% axes(handles.axes1); weiter ersteKurve setzen


hold on
handles.zweiteKurve = stairs(t,B,'g'); 
hold off

ymin = -1.8;
ymax = +1.8; %Maximum y-Achse
xmin=min(t);
xmax=max(t); %Maximum x-Achse
set(gca,'xlim',[xmin,xmax],'ylim',[ymin, ymax],'YTick',[]); %y-Achse ausblenden

% Die handles-struktur aktualisieren
guidata(hObject, handles);



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

% Die handles-struktur aktualisieren
guidata(hObject, handles);

% --- Executes during object creation, after setting all properties.
function zweiteKurve_CreateFcn(hObject, eventdata, handles)
% hObject    handle to zweiteKurve (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 zweiteKurve_down.
function zweiteKurve_down_Callback(hObject, eventdata, handles)
% hObject    handle to zweiteKurve_down (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% zc=(get(handles.zweiteKurve,'String')); 
    zc=str2double(get(handles.zweiteKurve,'String')); 
if (zc>1)
    zc=zc-1;
    set(handles.zweiteKurve,'String',zc);
end


handles = plotten_unten(hObject,handles);
% Die handles-struktur aktualisieren
guidata(hObject, handles);

% --- Executes on button press in zweiteKurve_up.
function zweiteKurve_up_Callback(hObject, eventdata, handles)
% hObject    handle to zweiteKurve_up (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% zc=(get(handles.zweiteKurve,'String')); 
zc=str2double(get(handles.zweiteKurve,'String')); 
if zc<2 
    zc=zc+1;
    set(handles.zweiteKurve,'String',zc);
end
handles = plotten_unten(hObject,handles);
% Die handles-struktur aktualisieren
guidata(hObject, handles);
