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

% Last Modified by GUIDE v2.5 21-Nov-2012 21:39:34

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

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

% Update handles structure
guidata(hObject, handles);
%axes(handles.diagram);
set(handles.diagram, 'Position', [100 3.5 150 39]);

%Anfangswerte setzen:
R_Anfang=5; %5 Ohm
C_Anfang=5; %5 µF
L_Anfang=5; %5 mH

set(handles.RWert,'String',R_Anfang);
set(handles.CWert,'String',C_Anfang);
set(handles.LWert,'String',L_Anfang);

set(handles.RSlider,'Value',R_Anfang);
set(handles.CSlider,'Value',C_Anfang);
set(handles.LSlider,'Value',L_Anfang);
% UIWAIT makes Momentanleistung wait for user response (see UIRESUME)
% uiwait(handles.figure1);


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


% --- Executes on selection change in FrequenzZeit.
function FrequenzZeit_Callback(hObject, eventdata, handles)
% hObject    handle to FrequenzZeit (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 FrequenzZeit contents as cell array
%        contents{get(hObject,'Value')} returns selected item from FrequenzZeit

contents = cellstr(get(hObject,'String'));



% --- Executes during object creation, after setting all properties.
function FrequenzZeit_CreateFcn(hObject, eventdata, handles)
% hObject    handle to FrequenzZeit (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



function new_plot_R(handles) %params beinhaltet alle Parameter die durch die GUI verstellbar sind
%wird aufgerufen sobald etwas verstellt wird, liest einmal alle Werte aus
%und startet die Berechnung und zeichnen neu

params.R=str2double(get(handles.RWert,'String'));

%zu Testzwecken
params.f=50;
data=Widerstand(params.R,params.f);

%x_width=get(handles.diagram,'Position')
axes(handles.diagram);
Leistungsdiagramme(data);

function new_plot_C(handles) %params beinhaltet alle Parameter die durch die GUI verstellbar sind
%wird aufgerufen sobald etwas verstellt wird, liest einmal alle Werte aus
%und startet die Berechnung und zeichnen neu

params.R=str2double(get(handles.RWert,'String'));
params.C=str2double(get(handles.CWert,'String'));
params.C=params.C*1e-7;

%zu Testzwecken
params.f=str2double(get(handles.FWert,'String'));
data=WiderstandKondensator(params.R,params.f,params.C);

%x_width=get(handles.diagram,'Position')
Leistungsdiagramme(data);

function new_plot_L(handles) %params beinhaltet alle Parameter die durch die GUI verstellbar sind
%wird aufgerufen sobald etwas verstellt wird, liest einmal alle Werte aus
%und startet die Berechnung und zeichnen neu

params.R=str2double(get(handles.RWert,'String'));
params.L=str2double(get(handles.LWert,'String'));
params.L=params.L*1e-3;


params.f=str2double(get(handles.FWert,'String'));
data=WiderstandKondensator(params.R,params.f);

Leistungsdiagramme(data);




function RWert_Callback(hObject, eventdata, handles)
% hObject    handle to RWert (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 RWert as text
%        str2double(get(hObject,'String')) returns contents of RWert as a double
R_Value=get(hObject,'String');
if isnumeric(R_Value)
    R_ValueNum=str2double(R_Value);
    if R_ValueNum<=10
        if R_ValueNum>=1
            set(handles.RSlider,'Value',R_ValueNum)
        end
    end
end

selected_Button=get(handles.AuswahlSchaltung,'SelectedObject');
new_plot_R(handles);

% --- Executes during object creation, after setting all properties.
function RWert_CreateFcn(hObject, eventdata, handles)
% hObject    handle to RWert (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');
set(hObject.String,'String',param);
end



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


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


% --- Executes during object creation, after setting all properties.
function LWert_CreateFcn(hObject, eventdata, handles)
% hObject    handle to LWert (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');
set(hObject.String,'String',param);
end


% --- Executes on slider movement.
function RSlider_Callback(hObject, eventdata, handles)
% hObject    handle to RSlider (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,'Value') returns position of slider
%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider
R_Value=get(hObject,'Value');
set(handles.RWert,'String',R_Value);
new_plot_R(handles);


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

% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor',[.9 .9 .9]);
end
set(hObject,'Min',1);
set(hObject,'Max',10);



% --- Executes on slider movement.
function CSlider_Callback(hObject, eventdata, handles)
% hObject    handle to CSlider (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,'Value') returns position of slider
%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider

C_Value=get(hObject,'Value');
C_Value=10^(-7+C_Value);
set(handles.CWert,'String',C_Value);
new_plot_C(handles)



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

% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor',[.9 .9 .9]);
end

set(hObject,'Min',1);
set(hObject,'Max',6);


% --- Executes on slider movement.
function LSlider_Callback(hObject, eventdata, handles)
% hObject    handle to LSlider (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,'Value') returns position of slider
%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider

L_Value=get(hObject,'Value');
set(handles.LWert,'String',L_Value);

% --- Executes during object creation, after setting all properties.
function LSlider_CreateFcn(hObject, eventdata, handles) %#ok<*INUSD,*DEFNU>
% hObject    handle to LSlider (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor',[.9 .9 .9]);
end
set(hObject,'Min',1);
set(hObject,'Max',10);


% --- Executes on slider movement.
function FSlider_Callback(hObject, eventdata, handles)
% hObject    handle to FSlider (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,'Value') returns position of slider
%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider
F_Value=get(hObject,'Value');
set(handles.FWert,'String',F_Value);

new_plot_C(handles)

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

% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor',[.9 .9 .9]);
end
set(hObject,'Min',1);
set(hObject,'Max',1000);



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

new_plot_C(handles)


% --- Executes during object creation, after setting all properties.
function FWert_CreateFcn(hObject, eventdata, handles)
% hObject    handle to FWert (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 when selected object is changed in AuswahlSchaltung.
function AuswahlSchaltung_SelectionChangeFcn(hObject, eventdata, handles)
% hObject    handle to the selected object in AuswahlSchaltung 
% eventdata  structure with the following fields (see UIBUTTONGROUP)
%	EventName: string 'SelectionChanged' (read only)
%	OldValue: handle of the previously selected object or empty if none was selected
%	NewValue: handle of the currently selected object
% handles    structure with handles and user data (see GUIDATA)
