clear all %löscht alle Variablen 
clear clc %löscht den Bildschirm

 
diagramoptions = [];
diagramlimits = [];
inputdata = [];

diagramoptions2 = [];
diagramlimits2 = [];
inputdata2 = [];

diagramoptions3 = [];
diagramlimits3 = [];
inputdata3 = [];

 

 
wholecontent = fileread('aaaa.txt')
sections = regexp(wholecontent, '\*+([^*]+)\*+([^*]+)', 'tokens')
counter=0; %Sollte mir die Anzahl der Diagramme zurückgeben 
for section = sections
   switch(strtrim(section{1}{1}))
       case 'Diagram Options' %Diagram Options -> siehe meine Gliederung im .txt file
          keyvalues = regexp(section{1}{2}, '([^\n\r=]+)=([^\n\r=]+)', 'tokens')%\n -> new line; \r carriage return
          diagramoptions = cell2table(vertcat(keyvalues{:}), 'VariableNames', {'Key', 'Value'}) 
          counter=counter+1;
       case 'Diagram Limits'
          header = strsplit(regexp(section{1}{2}, '[^\n\r]*', 'match', 'once'))
          content = textscan(section{1}{2}, repmat('%f', 1, numel(header)), 'HeaderLines', 2)
          diagramlimits = table(content{:}, 'VariableNames', header)
            
       case 'Input Data'
          inputdata = cell2mat(textscan(section{1}{2}, '%f%f%f', 'HeaderLines', 1))
          %output_inputdata(1) = inputdata;
        
       case 'Cutoff Lines1'
          cuttofflines1 = cell2mat(textscan(section{1}{2}, '%f%f%f', 'HeaderLines', 1))%Cutofflines  
          
          
       case 'Diagram Options2' %Diagram Options -> siehe meine Gliederung im .txt file
          keyvalues2 = regexp(section{1}{2}, '([^\n\r=]+)=([^\n\r=]+)', 'tokens')%\n -> new line; \r carriage return
          diagramoptions2 = cell2table(vertcat(keyvalues{:}), 'VariableNames', {'Key', 'Value'})
      
       
       case 'Diagram Limits2'
          header2 = strsplit(regexp(section{1}{2}, '[^\n\r]*', 'match', 'once'))
          content2 = textscan(section{1}{2}, repmat('%f', 1, numel(header2)), 'HeaderLines', 2)
          diagramlimits2 = table(content2{:}, 'VariableNames', header2)    
       
       case 'Input Data2'
          inputdata2 = cell2mat(textscan(section{1}{2}, '%f%f%f', 'HeaderLines', 1))
          %output_inputdata(2) = inputdata;
           
        case 'Diagram Options3' %Diagram Options -> siehe meine Gliederung im .txt file
          keyvalues3 = regexp(section{1}{2}, '([^\n\r=]+)=([^\n\r=]+)', 'tokens')%\n -> new line; \r carriage return
          diagramoptions3 = cell2table(vertcat(keyvalues{:}), 'VariableNames', {'Key', 'Value'})
             
       case 'Diagram Limits3'
          header3 = strsplit(regexp(section{1}{2}, '[^\n\r]*', 'match', 'once'))
          content3 = textscan(section{1}{2}, repmat('%f', 1, numel(header3)), 'HeaderLines', 2)
          diagramlimits3 = table(content3{:}, 'VariableNames', header3)
      
       
       case 'Input Data3'
          inputdata3 = cell2mat(textscan(section{1}{2}, '%f%f%f', 'HeaderLines', 1))%dh: ich habe 1 Headerline zur besseren übersicht
        
       case 'Input Data4'
          inputdata = cell2mat(textscan(section{1}{2}, '%f%f%f', 'HeaderLines', 1))
          %output_inputdata(1) = inputdata;   
          
      otherwise
          warning('Unknown section: %s', section{1}{1})
   end
end

%Abfr
%output_wsectionstart{1} = str2double(strsplit(diagramoptions.Value{strcmp(diagramoptions.Key, 'wsectionstart')}));
%output_wsectionstart{2} = str2double(strsplit(diagramoptions.Value{strcmp(diagramoptions2.Key, 'wsectionstart')}));
output_wsectionstart(1,:) = str2double(strsplit(diagramoptions.Value{strcmp(diagramoptions.Key, 'wsectionstart')}));
output_wsectionstart(2,:) = str2double(strsplit(diagramoptions.Value{strcmp(diagramoptions2.Key, 'wsectionstart')}));

d=213;
equivcycles(1,:)=str2double(diagramoptions.Value(strcmp(diagramoptions.Key, 'equivcycles')))
equivcycles(2,:)=str2double(diagramoptions.Value(strcmp(diagramoptions2.Key, 'equivcycles')))

inputdata1 = [ 3, 21, 7;
12, 21,  7;
3,  12,   7;
12,  7,  7;
3,  7,  7;
12, 3,   7];

inputdata2= [ 923, 224911, 27;
12, 21,  3247;
3243,  132,   73;
139242,  34327,  97;
32433,  93247,  39247;
9123924, 34233,   324237];



x(:,1) = inputdata1(:,1)
y(:,1) = inputdata1(:,2)
z(:,1) = inputdata1(:,3)
x(:,2) = inputdata2(:,1)
y(:,2) = inputdata2(:,2)
z(:,2) = inputdata2(:,3)
%equivcycles(1,:)=str2double(diagramoptions.Value(strcmp(diagramoptions.Key, 'equivcycles')))
%equivcycles(2,:)=str2double(diagramoptions.Value(strcmp(diagramoptions2.Key, 'equivcycles')))


%öffnet die output fenster
% openvar diagramoptions
% openvar diagramlimits 
% openvar inputdata 
 
%Auslesen ob log. Ordinate 
ordinatelogarithmic=diagramoptions.Value(strcmp(diagramoptions.Key, 'ordinatelogarithmic'))


test_value1=diagramlimits;%die ganzen Diagram Limits werden ausgelesen und auf
%die variable test_value1 geschrieben
test_value22 = diagramlimits(1,3) %(Zeile/Spalte)
test_value2 = diagramoptions(3,1) 
%test_value32 = diagramoptions(test_value2,{'Key'})%gibt die Key Spalte aus
%erer=diagramoptions.number_of_plots
%diagramoptions.number_of_plots(5)
test_value3 = diagramoptions(:,{'Key'})%gibt die Key Spalte aus
%test_value4 = diagramoptions('number_of_plots',{'Key'})%gibt die Key Spalte aus
%[match index] = ismember(diagramoptions,'number_of_plots'); 
%test_value4 = diagramoptions('Key'='number_of_plots',{'Value'})%gibt die Key Spalte aus

 
%************************************************************************
%************************************************************************
%Auslesen der diagram options -> Methode1
Tabel_Cell = table2cell(diagramoptions) ;
idx= strfind(Tabel_Cell(:,1), 'number_of_plots');
idx = find(not(cellfun('isempty',idx)));
number_of_plots = Tabel_Cell{idx,2}
%number_of_plots1=double(number_of_plots);
number_of_plots1=str2double(number_of_plots);

 
idx= strfind(Tabel_Cell(:,1), 'xlabel');
idx = find(not(cellfun('isempty',idx)));
xlabel1111 = Tabel_Cell{idx,2}

idx= strfind(Tabel_Cell(:,1), 'ylabel');
idx = find(not(cellfun('isempty',idx)));
ylabel111 = Tabel_Cell{idx,2}
%Methode 2
number_of_plots_methode_zwoa=diagramoptions.Value(strcmp(diagramoptions.Key, 'number_of_plots'))
number_of_plots_methode_zwoaw=diagramoptions.Value(strcmp(diagramoptions.Key, 'number_of_pts'))
%anscheinend die bessere methode
%************************************************************************
%************************************************************************
% 
% openvar diagramoptions2
% openvar diagramlimits2
% openvar inputdata2 
%  
% openvar diagramoptions3
% openvar diagramlimits3 
% openvar inputdata3 
 
 
%Rainflow Chart Darstellung:
%diagramoptions = cell2table(vertcat(keyvalues{:}), 'VariableNames', {'Key', 'Value'})

 
 
 
 
 
 
 
%Subplot Einstellungen
%fig = figure;
%fig.Units = 'centimeters';
%fig.Position(3:4) = [25  25];
%ax11 = axes('units', 'centimeters', 'position', [ 3, 21,  7,  7]);%Spalte 1 Reihe 1
%ax12 = axes('units', 'centimeters', 'position', [ 12, 21,  7,  7]);%Spalte 2 Reihe 1
%ax21 = axes('units', 'centimeters', 'position', [ 3,  12,  7,  7]);%Spalte 1 Reihe 2
%ax22 = axes('units', 'centimeters', 'position', [ 12,  12,  7,  7]);%Spalte 2 Reihe 2
%ax31 = axes('units', 'centimeters', 'position', [ 3,  3,  7,  7]);%Spalte 1 Reihe 3
%ax32 = axes('units', 'centimeters', 'position', [ 12, 3,  7,  7]);%Spalte 2 Reihe 3


%fig = figure;
fig = figure('Name','Page Header',...
    'Color',[0.431372559070587 0.815686285495758 0.7843137383461]);
fig.Units = 'centimeters';%%%%%%%%%%%%%%%%%%
fig.Position(3:4) = [25  25];
counter=6;%%% Soviele Diagramme habe ich zu plotten!
%https://itp.tugraz.at/LV/kernbich/AppSoft-1/appsoft1/node23.html
if counter==1%falls 1 Diagramm dargestellt werden soll                                            
  new_plotPositions =  [ 3, 3,  21,  21]  
else
 plotPositions = [ 3, 21,  8,  8;
                      12, 21,  8,  8;
                       3,  12,  8,  8;
                      12,  12,  8, 8;
                      3,  3,  8,  8;
                      12, 3,  8,  8];
%so sieht die richtige Anordnung aus
 new_plotPositions = plotPositions(1:counter,1:4);                  
%new_plotPositions = plotPositions(plotPositions<=12);%Mit diesem Befehl erzeuge ich mir die richtige Anordnung des 
%new_plotPositions(:);   
end  
%**********************************************************************



%   legend1 = legend('XXXX','XYZ','ZZW','YYYYYYYY','ZWZW','YZW','show'); 
  % set(legend1,'Position',[0.3775 0.1999 0.2857 0.1444]);

 
          



%**********************************************************************

nPlots=length(new_plotPositions);  % shorthand variable for convenience
hAx=zeros(nPlots,1);           % preallocate array for axes/subplot handles                  
 % for i = 1:length(new_plotPositions)
 for i = 1:size(new_plotPositions,1);
        if counter==1
        plotHandle = subplot(1, 1, i);
        else
        plotHandle = subplot(3, 2, i);
        end 
        plotHandle.Units = 'centimeters';
        plotHandle.Position = new_plotPositions(i,:);
%         plotHandle.Yscale='log'; %linear
%         plotHandle.Xscale='log';
%         plotHandle.XGrid = 'on';     
%         plotHandle.YGrid = 'on'; 
        if counter==1
            hAx(i)=subplot(1, 1, i);
        else
            hAx(i)=subplot(3, 2, i);
        end 
        box(subplot(3, 2, i),'on');
        hAx(i)=subplot(3, 2, i);  
        axis(hAx(i),[ -300 300 0 150]);
        set(subplot(3, 2, i),'Color',...
        [0 0 1]);
        set(subplot(3, 2, i),'FontAngle','italic');
        set(subplot(3, 2, i),'FontSize',11);
        set(subplot(3, 2, i),'FontWeight','bold');
        set(subplot(3, 2, i),'XMinorTick','on');
        set(subplot(3, 2, i),'XScale','linear');
        set(subplot(3, 2, i),'YScale','log');
        set(subplot(3, 2, i),'XColor',[1 1 0]);
        set(subplot(3, 2, i),'YColor',[1 1 0]); 
        title1=subplot(3, 2, i)
        title(title1,'Hallo')
        TextH = text(1, 1, 'Rechte obere Ecke', ... 
        'Units', 'normalized', ... 
        'VerticalAlignment', 'top', ... 
        'HorizontalAlignment', 'right');
  end


% Create textbox
annotation(fig,'textbox',...
    [0.550163179916317 0.143884892086331 0.25736820083682 0.166906474820144],...
    'FitBoxToText','off');

% Create textbox
annotation(fig,'textbox',...
    [0.0166903765690328 0.961151079136691 0.275150627615067 0.050359712230215],...
    'String','aaaaaaaaaaaaaaaaaaaaa',...
    'FontSize',20,...
    'FitBoxToText','off',...
    'EdgeColor','none');






%RAINFLOWDARSTELLUNG%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Input_Matrix = textread('Input1.txt')%liest die Daten für die Rainflow Darstellung ein

%[zeilen,spalten]=size(Input_Matrix)
%x = Input_Matrix(:,1)
%y = Input_Matrix(:,2)
%z = Input_Matrix(:,3)

 
x = inputdata(:,1)
y = inputdata(:,2)
z = inputdata(:,3)

 
 
 
%Definiert mir den Range des Diagramms...

axis ([ -500 500 0 222]);%manuelle Festlegung der Grenzen, hier solltest du
%die jeweiligen höheren Werte der Funktionen eintragen....... Was ist
%grösser? Rainflow oder Cutoff?

%colorbar('location','Manual', 'position', [0.93 0.1 0.02 0.81]);
az = 0;
el = 90;
view(az, el);
hold on
view(0,90)% view from above !!!http://de.mathworks.com/help/matlab/ref/view.html
a = 12;%markersize kannst einstellen welche grösse du haben willst ... 
%subplot(ax12)
subplot(3,2,2)
%colorbar('location','Manual', 'position', [0.93 0.1 0.02 0.81]);
scatter3(x, y, z, a, z, 'filled')
hold on
view(0, 90)
%Hier macht er die richtige sortierung für die korrekte darstellung.
%value = find(max(z)) ;
%hold on
%plot3(x(idx),y(idx),z(idx),'*r')
[m,ind]=max(z);
%subplot(ax12)
%subplot(3,2,2)
%colorbar('location','Manual', 'position', [0.93 0.1 0.02 0.81]);
colorbar
scatter3(x(ind), y(ind), z(ind),'*r');

 
 
 
grid on;%Gitter eingeschalten...
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
%***************** Wie man eine Linie zeichnet - Allgemeine Erklärung ***************************
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Hier die dicke braune "dummy Linie"
line([-350 -150],[20 20],[1000000000000 1000000000000],'Marker','.','LineStyle','-','LineWidth',9, 'Color',[.5 .4 .3])
%***************** Ende **************************************************
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

 
%********************Cutofflinien zeichnen********************************
%****************************************************************************************
%****************************************************************************************
%****************************************************************************************
%****************************************************************************************
%****************************************************************************************
%Initialisierungen für die Berechnungen:***********************************
sigma_wk = 50; % Default Wert angenommen
tau_wk = 70; % Default Wert angenommen
m_sigma = 0.07; % Steigung - Defaultwert angenommen
m_tau = 0.07; % Steigung - Defaultwert angenommen
m_sigma_zwei = m_sigma*0.33; % Steigung etwas flacher -> 1/3 von m_sigma -> vom Punkt 2 nach 3
m_tau_zwei = m_tau*0.33; % Steigung etwas flacher -> 1/3 von m_sigma -> vom Punkt 2 nach 3
multipikator=1.2;% Für das Zeichnen der Waagrechten Linien

%Normalspannungen:*********************************************************
%X-Koordianten der einzelnen Punkte
sigma_m_1=sigma_wk/(m_sigma-1);%Punkt1
sigma_m_2=sigma_wk/(1+m_sigma);%Punkt2
sigma_m_3=sigma_wk*((3+m_sigma)/(1+m_sigma_zwei)^2);%Punkt3
%Y-Werte der Punkte der einzelnen Punkte
sigma_a_1=sigma_wk/(1-m_sigma);%Punkt1
sigma_a_2=sigma_wk/(1+m_sigma);%Punkt2 Vorzeichen plus gemacht!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
sigma_a_3=(sigma_wk/3)*((3+m_sigma)/(1+m_sigma)^2);%Punkt3

%Schubspannungen***********************************************************
%X-Koordianten der einzelnen Punkte
tau_m_1=tau_wk/(m_tau-1);
tau_m_2=tau_wk/(1+m_tau);
tau_m_3=tau_wk*((3+m_tau)/(1+m_tau_zwei)^2);% 
%Y-Werte der Punkte der einzelnen Punkte
tau_a_1=tau_wk/(1-m_tau);
tau_a_2=tau_wk/(1+m_tau);
tau_a_3=(tau_wk/3)*((3+m_tau)/(1+m_tau)^2);

 
%Diagramm Beschriftungen***************************************************
%Farbauswahl http://www.avatar.se/molscript/doc/colour_names.html
title('\color[rgb]{0.698039 0.133333 0.133333}Normalspannungen - Schubspannungen');%Titel des Diagrammes.
ylabel('Beschriftung der y - Achse \color[rgb]{0 0.392157 0}\bf\sigma_{a}\tau_{a}');
%xlabel('Beschriftung der x - Achse \color[rgb]{0 0.392157 0}\bf\sigma_{m}\tau_{m}');

 
%number_of_plots_methode_zwoa=diagramoptions.Value(strcmp(diagramoptions.Key, 'number_of_plots'))
%Test
number_of_plots1=str2double(number_of_plots_methode_zwoa);
xlabel(number_of_plots1);

 
grid on; %Gitter eingeblendet
%axis ([ -5 5 0 5]);%manuelle Festlegung der
%Grenzen!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
%axis tight ;%Mit "..." werden die Bereiche wieder so gesetzt, dass die Daten perfekt in den Plot passen.
%Griechische Buchstaben https://de.mathworks.com/help/matlab/creating_plots/greek-letters-and-special-characters-in-graph-text.html?searchHighlight=greek
%http://matlab.izmiran.ru/help/techdoc/ref/linespec.html
%**************************************************************************

%Jetzt wird gezeichnet Schubspannungen und Normalspannungen (in einem Diagram )****************************************************
% X-Werte, Y-Werte, Z-Werte %Hier werden 2 Punkte im 3D Raum miteinander verbunden.....
%Z-Koordinaten wurde defaultmässig auf 1e7 gesetzt damit die cutoff linien
%deckend sind.

%Die Benennung der Punkte habe ich von der übernommen....
line([0 sigma_m_2],[sigma_wk sigma_a_2],[1e7 1e7],'Marker','.','LineStyle','-','LineWidth',1, 'Color',[1 0 0])% 0-2
line([sigma_m_2 sigma_m_3],[sigma_a_2 sigma_a_3],[1e7 1e7],'Marker','.','LineStyle','-','LineWidth',1, 'Color',[0 1 0])%2-3
line([0 sigma_m_1],[sigma_wk sigma_a_1],[1e7 1e7],'Marker','.','LineStyle','-','LineWidth',1, 'Color',[0 0 1])%0-1

%Waagrechte Linien: (mit dem Multiplikator habe ich defaultmässig
line([sigma_m_3 sigma_m_3*multipikator],[sigma_a_3 sigma_a_3],[1e7 1e7],'Marker','.','LineStyle','-','LineWidth',3, 'Color',[1 0 0])%Rechts
line([sigma_m_1 sigma_m_1*multipikator],[sigma_a_1 sigma_a_1],[1e7 1e7],'Marker','.','LineStyle','-','LineWidth',3, 'Color',[1 0 0])%Links

%Schubspannungen***********************************************************
line([0 tau_m_2],[tau_wk tau_a_2],[1e7 1e7],'Marker','.','LineStyle','-','LineWidth',5, 'Color',[0 1 1])
line([tau_m_2 tau_m_3],[tau_a_2 tau_a_3],[1e7 1e7],'Marker','.','LineStyle','-','LineWidth',5, 'Color',[0 0 1]) 
line([0 -tau_m_2],[tau_wk tau_a_2],[1e7 1e7],'Marker','.','LineStyle','-','LineWidth',5, 'Color',[1 0 1])
line([-tau_m_2 -tau_m_3],[tau_a_2 tau_a_3],[1e7 1e7],'Marker','.','LineStyle','-','LineWidth',5, 'Color',[0 1 1])
line([tau_m_3 tau_m_3*multipikator],[tau_a_3 tau_a_3],[1e7 1e7],'Marker','.','LineStyle','-','LineWidth',3, 'Color',[1 0 0])% %Waagrechte Linien: Rechts
line([-tau_m_3 -tau_m_3*multipikator],[tau_a_3 tau_a_3],[1e7 1e7],'Marker','.','LineStyle','-','LineWidth',3, 'Color',[1 0 0])% %Waagrechte Linien: Links
%****************************************************************************************
%****************************************************************************************
%****************************************************************************************
%**************************************************************************
%Hier erstelle ich die Cutofflinien
xx = cuttofflines1(:,1)%ich lese hier die x-Werte aller Punkte aus
yy = cuttofflines1(:,2)%ich lese hier die y-Werte aller Punkte aus
Size_cutofflines=size(xx,1);%Hier analysiere ich wieviele Punkte ich habe
default_value_z=1e7;%hier setze defaultmässig die z Komponente der Cutofflinien
hold on;
for index = 1:Size_cutofflines %hier zeichne die cutoff-lines 
    if (index==1)    
    line([xx(index) xx(index+1)],[yy(index) yy(index+1)],[default_value_z default_value_z],'Marker','.','LineStyle','-','LineWidth',3, 'Color',[1 1 0]);
    else
     line([xx(index-1) xx(index)],[yy(index-1) yy(index)],[default_value_z default_value_z],'Marker','.','LineStyle','-','LineWidth',3, 'Color',[1 0 0]);  
    end  
    hold on 
end

%**************************************************************************

 
 
hold off

 
 
 
 
 
 
%WÖHLER

%Input_Matrix_Woehler = textread('2.txt')
%x1 = Input_Matrix_Woehler(:,1)
%y1 = Input_Matrix_Woehler(:,2)

x1 = inputdata2(:,1)
y1 = inputdata2(:,2)

%*********************************
%Equivalentes Rechteck erzeugen:
%Input x2/y2
%x2=diagramoptions.Value(strcmp(diagramoptions.Key, 'equivcycles'))
%y2=diagramoptions.Value(strcmp(diagramoptions.Key, 'equivstress'))
%[xb2,yb2] = stairs(x2,y2);
%plot(yb2,xb2)
%xLimits = xlim;%hier hole ich mir den max. x-Wert der x-Achse
%yLimits = ylim;%hier hole ich mir den max. y-Wert der y-Achse

%*********************************

%xlim(axes1,[1000 200000000]);
%axis ([ 1000 1e7 0 130]);

 
% Create semilogx

 
% Uncomment the following line to preserve the X-limits of the axes

[xb,yb] = stairs(x1,y1);

 
 
%plot(xb,yb)
%CREATEFIGURE(X1, Y1)
%  X1:  vector of x data
%  Y1:  vector of y data

%  Auto-generated by MATLAB on 26-Sep-2016 15:00:15

% Create figure
%figure1 = figure('Name','Woehler',...
   % 'Color',[0.756862759590149 0.866666674613953 0.776470601558685]);

% Create axes
%axes1 = axes('Parent',figure1);
%hold(axes1,'on');

% Create semilogx

 
% Uncomment the following line to preserve the X-limits of the axes
% xlim(axes1,[1000 200000000]);
%box(axes1,'on');
% Set the remaining axes properties
%set(axes1,'Color',[0.894117653369904 0.941176474094391 0.901960790157318],...
%   'XMinorTick','on','XScale','log');
%axis ([ 1000 200000000 0 120]);%manuelle Festlegung der Grenzen, hier solltest du 
%subplot(ax11)
axis(subplot(3,2,1), [1000 1e8 0 130])
xlim(subplot(3,2,1), [1000 1e8])
%subplot(3,2,1)
%plot(yb,xb)
%axis(ax,'manual',1000 1e7 0 130)
plot(yb,xb)

%**************************************************************************
%Equivalentes Rechteck zeichnen!!!!
xLimits = xlim;
yLimits = ylim;
zLimits = zlim;
ymin=yLimits(1,1);
ymax=yLimits(1,2);
xmin=xLimits(1,1);
xmax=xLimits(1,2);
equivcycles=str2double(diagramoptions.Value(strcmp(diagramoptions.Key, 'equivcycles')))
equivstress=str2double(diagramoptions.Value(strcmp(diagramoptions.Key, 'equivstress')))
%raw a rectangle that has a lower left corner at (0,0) and an upper right corner at (2,4). Create the rectangle with curved corners by specifying the curvature as the scalar value 0.2. For data units of equal length along both the x-axis and y-axis, use axis equal.
rectangle('Position',[xmin ymin equivcycles equivstress],'Curvature',0.2)
%**************************************************************************
%Cutoff Linie zeichnen
cutoffvalue=str2double(diagramoptions.Value(strcmp(diagramoptions.Key, 'cutoffvalue')))
line([xmin xmax],[cutoffvalue cutoffvalue],[1 1],'Marker','.','LineStyle','-','LineWidth',1, 'Color',[0 0.3 1])
%**************************************************************************
%equivlabel
%text(equivcycles,equivstress,'\leftarrow \sigma_{äqu} = equivstress')
text(equivcycles,equivstress,['\sigma_{äqu}=',  num2str(equivstress)])
%**************************************************************************
%Test
x = [.50, .45];
y = [0.1, .74];
annotation('textarrow',x,y,'String','Formular XY')
%**************************************************************************
%Bestimmung des Maximums
x1 = inputdata2(:,1)
ymax_woehler=max(x1);%filtert das Maximum heraus
%text((xmax-xmin)/30,ymax_woehler,['\sigma_{a,1}=', num2str(ymax_woehler)])
text((xmax-xmin)/30,ymax_woehler,['\sigma_{a,1}=', num2str(ymax_woehler)])
%text(20,18,['\sigma_{a,1}=', num2str(ymax_woehler)])
%text(20,18,'\sigma_{a,1}= ymax_woehler')
%**************************************************************************
%schräger Pfeil + Formel
%x1=[0 50 75 100]%%%%%%%%%%%%%%%
%y1=[130 75 50 25]%%%%%%%%%%%%%%%%
%[xb,yb] = stairs(x1,y1);%%%%%%%%%%%%%%%
%plot(xb,yb)%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%h
xxx=annotation('textarrow',x,y,'String',' AaBbCc');
set(xxx,'parent',gca);
set(xxx,'position',[1e5 1e6 60 80]);
%x = [.3, .6];
%y = [.2, .7];
%annotation('textarrow',x,y,'String',' AaBbCc')
%**************************************************************************
%Woehler Linie plotten
%X = 1:0.5:1000000;%x values in the range  [1,1000000].
%Teil 1

%Woehler Abschnitte********************************************************
wsectionstart = str2double(strsplit(diagramoptions.Value{strcmp(diagramoptions.Key, 'wsectionstart')}));
wsectionsend = str2double(strsplit(diagramoptions.Value{strcmp(diagramoptions.Key, 'wsectionsend')}));
wsectionstartstress = str2double(strsplit(diagramoptions.Value{strcmp(diagramoptions.Key, 'wsectionstartstress')}));
wsectionlinestyle = strsplit(diagramoptions.Value{strcmp(diagramoptions.Key, 'wsectionlinestyle')});
wsectionslope = str2double(strsplit(diagramoptions.Value{strcmp(diagramoptions.Key, 'wsectionslope')}));%entspricht slope / steigung
[zeilen,elemente] = size(wsectionstart)
[zeilen2,elemente2] = size(wsectionsend)
[zeilen3,elemente3] = size(wsectionlinestyle)
[zeilen4,elemente4] = size(wsectionslope)

 
%kleine Abfrage ob die Anzahl der benötigten dinge vorhanden sind
if (elemente  == elemente2 == elemente3 == elemente4 )
disp(' ')
else
disp('falsche Dimension')
end

%Dashed / Const?

 
hold on;

%Hier zeichne ich die Woehler-Abschnitte
for index = 1:elemente

%Abfrage ob dashed oder cont
if strcmp(wsectionlinestyle(index),'dashed')
    line_style=''
else
    line_style='--'
end   
 
rate=(wsectionsend(index)-wsectionstart(index))/100;
x=(wsectionstart(index):rate:wsectionsend(index));%Zahlengerade für x
part_solution=wsectionstartstress(index)*(5000000 ./x);
solution=part_solution.^(1/wsectionslope(index));
plot(x,solution,line_style)
hold on
end

%**************************************************************************

 
 
 
 
clear clc

 
%wsectionstart=nanmean(str2double(diagramoptions.Value(strcmp(diagramoptions.Key, 'wsectionstart'))))
%wsectionstart = str2double(diagramoptions.Value(strcmp(diagramoptions.Key, 'wsectionstart')));
wsectionstart = str2double(strsplit(diagramoptions.Value{strcmp(diagramoptions.Key, 'wsectionstart')}));
wsectionend=str2double(diagramoptions.Value(strcmp(diagramoptions.Key, 'wsectionend')))
wsectionlinestyle=diagramoptions.Value(strcmp(diagramoptions.Key, 'wsectionlinestyle'))
wsectionstartstress=diagramoptions.Value(strcmp(diagramoptions.Key, 'wsectionstartstress'))
wsectionslope=diagramoptions.Value(strcmp(diagramoptions.Key, 'wsectionslope'))

 
 
hold on;
x=(90000:20:50000000);
B = 1/3;
C=58.02349610358*(5000000 ./x);
y=C.^B;
plot(x,y)
%Teil 2 Strichlierter Teil
hold on;
x=(50000000:20:40000000);
B = 1/3;
C=58.02349610358*(5000000 ./x);
y=C.^B;
plot(x,y,'--')

 
%**************************************************************************
%plot(x1,y1)


%[dummy ID]=sort(z);
%colors=colormap(jet(length(z)));

%figure
%for i=1:length(z)
%plot(x(i),y(i),'s','MarkerFaceColor',colors(ID(i),:));
%hold on
%end

% subplot(3,2,3)
% subplot(3,2,4)
% subplot(3,2,5)
% subplot(3,2,6)

 
 
 
datacursormode on %damit ich die punkte im diagram anclicken kann und die jeweiligen werte angezeigt bekomme .....
%figure('units','centimeters','position',[3 3 5 5])

 
 
 
 
 
 
 
%{

%Subplot Einstellungen
fig = figure;
fig.Units = 'centimeters';
fig.Position(3:4) = [25  25];
ax11 = axes('units', 'centimeters', 'position', [ 3, 21,  7,  7]);%Spalte 1 Reihe 1
ax12 = axes('units', 'centimeters', 'position', [ 12, 21,  7,  7]);%Spalte 2 Reihe 1
ax21 = axes('units', 'centimeters', 'position', [ 3,  12,  7,  7]);%Spalte 1 Reihe 2
ax22 = axes('units', 'centimeters', 'position', [ 12,  12,  7,  7]);%Spalte 2 Reihe 2
ax31 = axes('units', 'centimeters', 'position', [ 3,  3,  7,  7]);%Spalte 1 Reihe 3
ax32 = axes('units', 'centimeters', 'position', [ 12, 3,  7,  7]);%Spalte 2 Reihe 3

 
 
 
%RAINFLOWDARSTELLUNG%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%Subplot Einstellungen
%fig = figure;
%fig.Units = 'centimeters';
%fig.Position(3:4) = [25  25];
%ax11 = axes('units', 'centimeters', 'position', [ 3, 21,  7,  7]);%Spalte 1 Reihe 1
%ax12 = axes('units', 'centimeters', 'position', [ 12, 21,  7,  7]);%Spalte 2 Reihe 1
%ax21 = axes('units', 'centimeters', 'position', [ 3,  12,  7,  7]);%Spalte 1 Reihe 2
%ax22 = axes('units', 'centimeters', 'position', [ 12,  12,  7,  7]);%Spalte 2 Reihe 2
%ax31 = axes('units', 'centimeters', 'position', [ 3,  3,  7,  7]);%Spalte 1 Reihe 3
%ax32 = axes('units', 'centimeters', 'position', [ 12, 3,  7,  7]);%Spalte 2 Reihe 3

fig = figure;
fig.Units = 'centimeters';
fig.Position(3:4) = [25  25];
plotPositions = [ 3, 21,  7,  7;
                      12, 21,  7,  7;
                       3,  12,  7,  7;
                      12,  12,  7,  7;
                      3,  3,  7,  7;
                      12, 3,  7,  7];
nPlots=length(plotPositions);  % shorthand variable for convenience
hAx=zeros(nPlots,1);           % preallocate array for axes/subplot handles                  
  for i = 1:length(plotPositions)
        plotHandle = subplot(3, 2, i);
        plotHandle.Units = 'centimeters';
        plotHandle.Position = plotPositions(i,:);
        hAx(i)=subplot(3, 2, i);  
        axis(hAx(i),[ -300 300 0 150]); %
  end
%RAINFLOWDARSTELLUNG%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Input_Matrix = textread('Input1.txt')%liest die Daten für die Rainflow Darstellung ein
[zeilen,spalten]=size(Input_Matrix)
x = Input_Matrix(:,1)
y = Input_Matrix(:,2)
z = Input_Matrix(:,3)

%Definiert mir den Range des Diagramms...

axis ([ -500 500 0 222]);%manuelle Festlegung der Grenzen, hier solltest du
%die jeweiligen höheren Werte der Funktionen eintragen....... Was ist
%grösser? Rainflow oder Cutoff?

%colorbar('location','Manual', 'position', [0.93 0.1 0.02 0.81]);
az = 0;
el = 90;
view(az, el);
hold on
view(0,90)% view from above !!!http://de.mathworks.com/help/matlab/ref/view.html
a = 12;%markersize kannst einstellen welche grösse du haben willst ... 
%subplot(ax12)
subplot(3,2,2)
%colorbar('location','Manual', 'position', [0.93 0.1 0.02 0.81]);
scatter3(x, y, z, a, z, 'filled')
hold on
view(0, 90)
%Hier macht er die richtige sortierung für die korrekte darstellung.
%value = find(max(z)) ;
%hold on
%plot3(x(idx),y(idx),z(idx),'*r')
[m,ind]=max(z);
%subplot(ax12)
%subplot(3,2,2)
%colorbar('location','Manual', 'position', [0.93 0.1 0.02 0.81]);
colorbar
scatter3(x(ind), y(ind), z(ind),'*r');

 %***************** Wie man eine Linie zeichnet - Allgemeine Erklärung ***************************
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Hier die dicke braune "dummy Linie"
line([-350 -150],[20 20],[2000000 2000000],'Marker','.','LineStyle','-','LineWidth',9, 'Color',[.5 .4 .3])
%***************** Ende **************************************************
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

 
%********************Cutofflinien zeichnen********************************
%****************************************************************************************
%****************************************************************************************
%****************************************************************************************
%****************************************************************************************
%****************************************************************************************
%Initialisierungen für die Berechnungen:***********************************
sigma_wk = 50; % Default Wert angenommen
tau_wk = 70; % Default Wert angenommen
m_sigma = 0.07; % Steigung - Defaultwert angenommen
m_tau = 0.07; % Steigung - Defaultwert angenommen
m_sigma_zwei = m_sigma*0.33; % Steigung etwas flacher -> 1/3 von m_sigma -> vom Punkt 2 nach 3
m_tau_zwei = m_tau*0.33; % Steigung etwas flacher -> 1/3 von m_sigma -> vom Punkt 2 nach 3
multipikator=1.2;% Für das Zeichnen der Waagrechten Linien

%Normalspannungen:*********************************************************
%X-Koordianten der einzelnen Punkte
sigma_m_1=sigma_wk/(m_sigma-1);%Punkt1
sigma_m_2=sigma_wk/(1+m_sigma);%Punkt2
sigma_m_3=sigma_wk*((3+m_sigma)/(1+m_sigma_zwei)^2);%Punkt3
%Y-Werte der Punkte der einzelnen Punkte
sigma_a_1=sigma_wk/(1-m_sigma);%Punkt1
sigma_a_2=sigma_wk/(1+m_sigma);%Punkt2 Vorzeichen plus gemacht!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
sigma_a_3=(sigma_wk/3)*((3+m_sigma)/(1+m_sigma)^2);%Punkt3

%Schubspannungen***********************************************************
%X-Koordianten der einzelnen Punkte
tau_m_1=tau_wk/(m_tau-1);
tau_m_2=tau_wk/(1+m_tau);
tau_m_3=tau_wk*((3+m_tau)/(1+m_tau_zwei)^2);% 
%Y-Werte der Punkte der einzelnen Punkte
tau_a_1=tau_wk/(1-m_tau);
tau_a_2=tau_wk/(1+m_tau);
tau_a_3=(tau_wk/3)*((3+m_tau)/(1+m_tau)^2);

 
%Diagramm Beschriftungen***************************************************
%Farbauswahl http://www.avatar.se/molscript/doc/colour_names.html
title('\color[rgb]{0.698039 0.133333 0.133333}Normalspannungen - Schubspannungen');%Titel des Diagrammes.
ylabel('Beschriftung der y - Achse \color[rgb]{0 0.392157 0}\bf\sigma_{a}\tau_{a}');
xlabel('Beschriftung der x - Achse \color[rgb]{0 0.392157 0}\bf\sigma_{m}\tau_{m}');
grid on; %Gitter eingeblendet
%axis ([ -5 5 0 5]);%manuelle Festlegung der
%Grenzen!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
%axis tight ;%Mit "..." werden die Bereiche wieder so gesetzt, dass die Daten perfekt in den Plot passen.
%Griechische Buchstaben https://de.mathworks.com/help/matlab/creating_plots/greek-letters-and-special-characters-in-graph-text.html?searchHighlight=greek
%http://matlab.izmiran.ru/help/techdoc/ref/linespec.html
%**************************************************************************

%Jetzt wird gezeichnet Schubspannungen und Normalspannungen (in einem Diagram )****************************************************
% X-Werte, Y-Werte, Z-Werte %Hier werden 2 Punkte im 3D Raum miteinander verbunden.....
%Z-Koordinaten wurde defaultmässig auf 1e7 gesetzt damit die cutoff linien
%deckend sind.

%Die Benennung der Punkte habe ich von der übernommen....
line([0 sigma_m_2],[sigma_wk sigma_a_2],[1e7 1e7],'Marker','.','LineStyle','-','LineWidth',1, 'Color',[1 0 0])% 0-2
line([sigma_m_2 sigma_m_3],[sigma_a_2 sigma_a_3],[1e7 1e7],'Marker','.','LineStyle','-','LineWidth',1, 'Color',[0 1 0])%2-3
line([0 sigma_m_1],[sigma_wk sigma_a_1],[1e7 1e7],'Marker','.','LineStyle','-','LineWidth',1, 'Color',[0 0 1])%0-1

%Waagrechte Linien: (mit dem Multiplikator habe ich defaultmässig
line([sigma_m_3 sigma_m_3*multipikator],[sigma_a_3 sigma_a_3],[1e7 1e7],'Marker','.','LineStyle','-','LineWidth',3, 'Color',[1 0 0])%Rechts
line([sigma_m_1 sigma_m_1*multipikator],[sigma_a_1 sigma_a_1],[1e7 1e7],'Marker','.','LineStyle','-','LineWidth',3, 'Color',[1 0 0])%Links

%Schubspannungen***********************************************************
line([0 tau_m_2],[tau_wk tau_a_2],[1e7 1e7],'Marker','.','LineStyle','-','LineWidth',5, 'Color',[0 1 1])
line([tau_m_2 tau_m_3],[tau_a_2 tau_a_3],[1e7 1e7],'Marker','.','LineStyle','-','LineWidth',5, 'Color',[0 0 1]) 
line([0 -tau_m_2],[tau_wk tau_a_2],[1e7 1e7],'Marker','.','LineStyle','-','LineWidth',5, 'Color',[1 0 1])
line([-tau_m_2 -tau_m_3],[tau_a_2 tau_a_3],[1e7 1e7],'Marker','.','LineStyle','-','LineWidth',5, 'Color',[0 1 1])
line([tau_m_3 tau_m_3*multipikator],[tau_a_3 tau_a_3],[1e7 1e7],'Marker','.','LineStyle','-','LineWidth',3, 'Color',[1 0 0])% %Waagrechte Linien: Rechts
line([-tau_m_3 -tau_m_3*multipikator],[tau_a_3 tau_a_3],[1e7 1e7],'Marker','.','LineStyle','-','LineWidth',3, 'Color',[1 0 0])% %Waagrechte Linien: Links
%****************************************************************************************
%****************************************************************************************
%****************************************************************************************

datacursormode on %damit ich die punkte im diagram anclicken kann und die jeweiligen werte angezeigt bekomme .....
figure('units','centimeters','position',[3 3 5 5])

 
grid on;%Gitter eingeschalten...

subplot(3, 2, 1); 
Input_Matrix_Woehler = textread('2.txt')
x1 = Input_Matrix_Woehler(:,1)
y1 = Input_Matrix_Woehler(:,2)
[xb,yb] = stairs(x1,y1);
%plot(xb,yb)
%CREATEFIGURE(X1, Y1)
%  X1:  vector of x data
%  Y1:  vector of y data

%  Auto-generated by MATLAB on 26-Sep-2016 15:00:15

% Create figure
figure1 = figure('Name','Woehler',...
    'Color',[0.756862759590149 0.866666674613953 0.776470601558685]);

% Create axes
axes1 = axes('Parent',figure1);
hold(axes1,'on');

% Create semilogx

 
% Uncomment the following line to preserve the X-limits of the axes
xlim(axes1,[1000 200000000]);
box(axes1,'on');
% Set the remaining axes properties
set(axes1,'Color',[0.894117653369904 0.941176474094391 0.901960790157318],...
    'XMinorTick','on','XScale','log');

plot(yb,xb)

%plot(x1,y1)

%https://plot.ly/alpha/workspace/

%[dummy ID]=sort(z);
%colors=colormap(jet(length(z)));

%figure
%for i=1:length(z)
%plot(x(i),y(i),'s','MarkerFaceColor',colors(ID(i),:));
%hold on
%end

 
 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%}
