function Data
 	speed;
    
 	%miete;
end
 
function speed
    clc
    [number speed run expt] = textread('Daten/michelson.dat','%d %d %d %d','headerlines' ,1);
    %nur erstes Experiment
    ind = (expt==1);
    s = speed(find(ind));
    mean(s)
    std(s)
    median(s)
    mad(s)
    skew = inline('((sqrt(length(x))*sum((x-mean(x)).^3))/(sum((x-mean(x)).^2))^(3/2))', 'x')
    %function y = skew(x)
    %    y = ((sqrt(length(x))*sum((x-mean(x)).^3))/(sum((x-mean(x)).^2))^(3/2));
    %end
    
    skew(s)
    
    figure('name','Box-Plot Types')
    subplot(1,3,1)
    boxplot(s)
    subplot(1,3,2)
    boxplot(s,'notch','on','whisker',1)
    subplot(1,3,3)
    boxplot(s,'plotstyle','compact')
    hold off
    
    figure('name','Boxplot Daten')
    boxplot(speed, expt)
    xlabel('Exp.Nummer')
    ylabel('Speed')
    
    strim = speed(find(s>700));
    mean(strim)
    std(strim)
    
    figure('name','Q-Q-Plot')
    qqplot(s)
    
    disp('t-test')
    [h,p,ci] = ttest2(speed(find(expt==1)),speed(find(expt==2)))
    
    %Speed-Measure
    disp(' ### Speed Messungen ###')
    %Test-Daten 20 mal Replizieren
    speed = repmat(speed,20, 1);
    
    sc = [];
    tic
    sc= ((speed+299000)/299734).^2;
    t = toc
    
    sc = [];
    tic
    sc = arrayfun(@(x)(((x+299000)/299734).^2), speed);
    t = toc
    
    sc = [];
    tic
    sc = feval(@(x)(((x+299000)/299734).^2), speed);
    t = toc
    
    sc = [];
    tic
    for i=1:length(speed)
            sc(i) = ((speed(i)+299000)/299734)^2;
    end
    t = toc
end

function miete
    clc
	%multivariate daten
    [GKM QMKM QM Zi BJ B L best WW ZH BK BA KUE] =  ...
        textread('Daten/miete03p.csv','%f %f %d %d %f %d %d %d %d %d %d %d %d','headerlines' ,1,'delimiter','\t');
    %Einsortieren in Klasse 1-6
    BJKL = 1 + (BJ>1918)+(BJ>1948)+(BJ>1965)+(BJ>1977)+(BJ>1983);
    %Einsortieren in Klasse 1-3
    QMKL = 1 + (QM > 50) + (QM > 80) ;
    
    figure('name','Miete')
    hold on
    plot(QM, GKM, 'o')
    plot([0 max(QM)], [0 mean(QMKM)*max(QM)],'-k','LineWidth',2)
    plot([0 max(QM)], [0 (mean(QMKM)+std(QMKM))*max(QM)],'-r')
    plot([0 max(QM)], [0 (mean(QMKM)-std(QMKM))*max(QM)],'-r')
 
    z = [mean(QMKM(find(QMKL==1))) mean(QMKM(find(QMKL==2))) mean(QMKM(find(QMKL==3)))];
    
    plot([0 50], [0 z(1)*50], '-y','LineWidth',2)
    plot([50 80], [z(2)*50 z(2)*80], '-g','LineWidth',2)
    plot([80 200], [z(3)*80 z(3)*200], '-m','LineWidth',2)
    
    %Regressionsgerade
    p = polyfit(QM, GKM, 1);
    x = [0 200];
    y = polyval(p,x);
    plot(x,y,'-.r','LineWidth',2)
    hold off
    
    
    figure('name','Stack-Bar-Plot')
    data = zeros(6,3);
    for i=1:6
        for k=1:3
            data(i,k) = sum (find(BJKL(find(QMKL==k))==i));
        end
        
    end
    subplot(1,2,1)
    bar(data,'stack')
    set(gca,'YTickLabel',[1 2 3])
    scale = max(sum(data'))./sum(data');
    data = (ones(3,1)*scale).*data';
    subplot(1,2,2)
    bar(data','stack')
    set(gca,'YTickLabel',[1 2 3]) 
    
  
    QMKMKL = 1 + (QMKM > 8) + (QMKM > 10) + (QMKM > 12) ;
    figure('name','Stack-Bar-Plot')
    data = zeros(6,2);
    for i=1:6 
        data(i,1) = sum (find(QMKMKL(find(L))==i));
        data(i,2) = sum (find(QMKMKL(find(1-L))==i));
    end
    subplot(1,2,1)
    bar(data,'stack')
    set(gca,'YTickLabel',[1 2])
    scale = max(sum(data'))./sum(data');
    data = (ones(2,1)*scale).*data';
    subplot(1,2,2)
    bar(data','stack')
    set(gca,'YTickLabel',[1 2]) 
    
    %Pie-Chart
    figure('name','Pie-Chart')
    h = zeros(1,6);
    for i=1:6
        h(i) = length(find(BJKL==i));
    end
    subplot(1,2,1)
    pie(h,{'vor 1919','1919-1948','1949-1965','1966-1977','1978-1983','Neubau'});
    subplot(1,2,2)
    bar(h)
end
