function varargout = Impendanzen(varargin)
% IMPENDANZEN MATLAB code for Impendanzen.fig
%      IMPENDANZEN, by itself, creates a new IMPENDANZEN or raises the existing
%      singleton*.
%
%      H = IMPENDANZEN returns the handle to a new IMPENDANZEN or the handle to
%      the existing singleton*.
%
%      IMPENDANZEN('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in IMPENDANZEN.M with the given input arguments.
%
%      IMPENDANZEN('Property','Value',...) creates a new IMPENDANZEN or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before Impendanzen_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to Impendanzen_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 Impendanzen

% Last Modified by GUIDE v2.5 19-Feb-2014 10:38:19

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @Impendanzen_OpeningFcn, ...
                   'gui_OutputFcn',  @Impendanzen_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 Impendanzen is made visible.
function Impendanzen_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 Impendanzen (see VARARGIN)

%Festlegung der Strings in den Popupmenü Bauteil und Belastung

set(handles.Bauteil,'String',{'Platte','Stab','Test'});
set(handles.Belastung,'String',{'longitudinal','Belastung mittig','Belastung Kante'});


% Choose default command line output for Impendanzen
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes Impendanzen wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = Impendanzen_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 selection change in Bauteil.
function Bauteil_Callback(hObject, eventdata, handles)
% hObject    handle to Bauteil (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
Bauteile_Liste = get(hObject, 'String');
Auswahl_position = get(hObject, 'Value');
Bauteil = Bauteile_Liste{Auswahl_position};

switch(Bauteil)
   case 'Platte'
       set(handles.Material, 'String', {'GKB', 'GKF','FPY','OSB','Stahl','Beton','Glas','BSP'});     %Plattenauswahl für Popupmenübauteil
   otherwise
       set(handles.Material, 'String', {'Fichtenstab', 'Eichenstab', 'Metallstab'})                 %Stabauswahl für Popupmenübauteil
end
 
handles.Bauteil = Bauteil;
guidata(hObject, handles); 






% --- Executes during object creation, after setting all properties.
function Bauteil_CreateFcn(hObject, eventdata, handles)
% hObject    handle to Bauteil (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



% --- Executes on selection change in Material.
function Material_Callback(hObject, eventdata, handles)
% hObject    handle to Material (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

Material = get(hObject,'Value');
handles.Material = Material;
guidata(hObject, handles);


% --- Executes during object creation, after setting all properties.
function Material_CreateFcn(hObject, eventdata, handles)
% hObject    handle to Material (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 Breite_Callback(hObject, eventdata, handles)
% hObject    handle to Breite (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

Breite_mm = str2double(get(hObject,'String'));
handles.Breite = Breite_mm/1000;
guidata(hObject, handles);

% --- Executes during object creation, after setting all properties.
function Breite_CreateFcn(hObject, eventdata, handles)
% hObject    handle to Breite (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 Dicke_Callback(hObject, eventdata, handles)
% hObject    handle to Dicke (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

Dicke_mm = str2double(get(hObject,'String'));
handles.Dicke = Dicke_mm/1000;
guidata(hObject, handles);

% --- Executes during object creation, after setting all properties.
function Dicke_CreateFcn(hObject, eventdata, handles)
% hObject    handle to Dicke (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 selection change in Belastung.
function Belastung_Callback(hObject, eventdata, handles)
% hObject    handle to Belastung (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

Belastung = get(hObject,'String');
handles.Belastung = Belastung;
guidata(hObject, handles);


% --- Executes during object creation, after setting all properties.
function Belastung_CreateFcn(hObject, eventdata, handles)
% hObject    handle to Belastung (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


% --- Executes on button press in Ausgabe.
function Ausgabe_Callback(hObject, eventdata, handles)
% hObject    handle to Ausgabe (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
guidata(hObject, handles);

% Initialisierung der Materialdaten Platte

str_material(1) = struct('name','GKP','Emodul',2400,'Dichte',800,'Poisson',0.3,'intVerlustfaktor',0.01)  ;
str_material(2) = struct('name','GFP','Emodul',3300,'Dichte',1150,'Poisson',0.30,'intVerlustfaktor',0.010)  ;
str_material(3) = struct('name','FPY','Emodul',3600,'Dichte',650,'Poisson',0.35,'intVerlustfaktor',0.022)  ;
str_material(4) = struct('name','OSB','Emodul',2000,'Dichte',600,'Poisson',0.05,'intVerlustfaktor',0.02)  ;
str_material(5) = struct('name','Stahl','Emodul',200000,'Dichte',7850,'Poisson',0.3,'intVerlustfaktor',0.001)  ;
str_material(6) = struct('name','Beton','Emodul',20000,'Dichte',2300,'Poisson',0.3,'intVerlustfaktor',0.006)  ;
str_material(7) = struct('name','Glas','Emodul',80000,'Dichte',2500,'Poisson',0.2,'intVerlustfaktor',0.001)  ;
str_material(8) = struct('name','BSP','Emodul',11000,'Dichte',450,'Poisson',0.2,'intVerlustfaktor',0.01)  ;

%Initialisierung der Materialdaten Stab 

%str_material(9) = struct('name','Fichten Stab','Emodul',11000,'Dichte',450,'Poisson',0.2,'intVerlustfaktor',0.01);
%str_material(10) = struct('name','Eichen Stab','Emodul',11000,'Dichte',450,'Poisson',0.2,'intVerlustfaktor',0.01);

Material = handles.Material;
Breite = handles.Breite;
Dicke = handles.Dicke; 
Belastung = handles.Belastung; 


xlabel('Frequenz in Hz'); 

%Festlegung des Plotintervalls/ Frequenzbereich

Frequenzbereich = 50:5000; 


%Aufbauprinzip:  if( Bauteilvergleich    &&    Belastungstypvergleich) 

if (all(strcmp(handles.Bauteil, 'Platte') == 1) && all(strcmp(Belastung, 'longitudinal')) == 1 ) 
  
   Fehlermeldung = errordlg('ungültige Belastung','Fehler'); 
   plot(Frequenzbereich,Fehlermeldung)
     
elseif (all(strcmp(handles.Bauteil, 'Platte')) ==1 && all(strcmp(Belastung, 'Belastung mittig')) == 1 )
    
    Realteil = 8* (str_material(Material).Dichte * str_material(Material).Emodul * Dicke^4 /(12*(1-(str_material(Material).Poisson)^2)))^0.5; 
    Imaginaerteil = 0; 
    Betrag = abs(Realteil);
    
    %Erzeugung der Handles für die axes und der Plots
    
    axes(handles.Realteil);
    plot(Frequenzbereich, Realteil)   
    
    axes(handles.Imaginaerteil);
    plot(Frequenzbereich,Imaginaerteil) 
    
    axes(handles.Betrag);
    plot(Frequenzbereich, Betrag) 
    
elseif (all(strcmp(handles.Bauteil, 'Platte')) == 1 && all(strcmp(Belastung, 'Belastung Kante')) == 1) 
    
    Realteil = 3.5* (str_material(Material).Dichte * str_material(Material).Emodul * Dicke^4 /(12*(1-(str_material(Material).Poisson)^2)))^0.5 ;
    Imaginaerteil = 0; 
    Betrag = abs(Realteil);
    
   %Erzeugung der Handles für die axes und der Plots
    cla;                                            %Plotinhalt löschen
    axes(handles.Realteil);
    plot(Frequenzbereich, Realteil)   
    
    axes(handles.Imaginaerteil);
    plot(Frequenzbereich,Imaginaerteil)
    
    axes(handles.Betrag);
    plot(Frequenzbereich, Betrag) 
elseif ( all(strcmp(handles.Bauteil, 'Stab')) == 1 && all(strcmp(Belastung, 'longitudinal')) == 1) %Für Stäbe 
        
    Realteil = Dichte * Dicke * Breite * Lambda_L * Frequenzbereich; 
    Imaginaerteil = 0; 
    Betrag = abs(Realteil);
    
    %Erzeugung der Handles für die axes und der Plots
    cla;                                            %Plotinhalt löschen
    axes(handles.Realteil);
    plot(Frequenzbereich, Realteil)   
    
    axes(handles.Imaginaerteil);
    plot(Frequenzbereich,Imaginaerteil) 
    
    axes(handles.Betrag);
    plot(Frequenzbereich, Betrag) 
    
elseif ( all(strcmp(handles.Bauteil, 'Stab')) == 1 && all(strcmp(Belastung, 'Belastung mittig')) == 1) %Für Stäbe mittige Belastung
        
    Realteil = 2 * (Dichte * Dicke * Breite)^0.75 * (2*pi* Frequenzbereich)^0.5 * (Breite * (Dicke)^3 * str_material(Material).Emodul * 10^6 /12 )^(0.25); 
    Imaginaerteil =  2 * (Dichte * Dicke * Breite)^0.75 * (2*pi* Frequenzbereich)^0.5 * (Breite * (Dicke)^3 * str_material(Material).Emodul * 10^6 /12 )^(0.25);
    Betrag = abs(Realteil) * 2^(0.5);
    
%Erzeugung der Handles für die axes und der Plots
    cla;                                            %Plotinhalt löschen
    axes(handles.Realteil);
    plot(Frequenzbereich, Realteil)   
    
    axes(handles.Imaginaerteil);
    plot(Frequenzbereich,Imaginaerteil) 
    
    axes(handles.Betrag);
    plot(Frequenzbereich, Betrag)
    
elseif ( all(strcmp(handles.Bauteil, 'Stab')) == 1 && all(strcmp(Belastung, 'Belastung Kante')) == 1) %Für Stäbe Kanten Belastung
        
    Realteil = 0.5 * (Dichte * Dicke * Breite)^0.75 * (2*pi* Frequenzbereich)^0.5 * (Breite * Dicke^3 * str_material(Material).Emodul * 10^6 /12 )^(0.25);
    Imaginaerteil = 0.5 * (Dichte * Dicke * Breite)^0.75 * (2*pi* Frequenzbereich)^0.5 * (Breite * Dicke^3 * str_material(Material).Emodul * 10^6 /12 )^(0.25);
    Betrag = abs(Realteil) * 2^(0.5);
    
%Erzeugung der Handles für die axes und der Plots
    cla;                                            %Plotinhalt löschen
    axes(handles.Realteil);
    plot(Frequenzbereich, Realteil)   
    
    axes(handles.Imaginaerteil);
    plot(Frequenzbereich,Imaginaerteil) 
    
    axes(handles.Betrag);
    plot(Frequenzbereich, Betrag) 
    
end 
    


