function [B] = mittlererbestand(A)

%A = xlsread('test.xls');
A = round(A)
a = max(A(:,2)); % Maximum of column 2
b = max(A(:,3)); % Maximum of column 3

if a>=b,
totaltime=a
elseif a<b,
totaltime=b %defines timecounter
end
[m,n]= size(A) %m: rows, n: columns


content1=0; %content item1
content2=0; %content item2
content3=0; %content item3
content=0;  %total content 

t=0

B(1,1)=t
B(1,2)=content
B(1,3)=content1
B(1,4)=content2
B(1,5)=content3

t=1; %time counter 

B =zeros(totaltime,5) %m x 5 Matrix with zeros 

while t<=totaltime,
    r=1; %rowcounter
    while r<=m,
        if A(r,2)== t,
            content = content + 1
            if A(r,1) == 1,
                content1 = content1 + 1
            end
             if A(r,1) == 2,
                content2 = content2 + 1
             end
             if A(r,1) == 3,
                content3 = content3 + 1
            end
        end
        if A(r,3)==t, 
            content = content - 1
              if A(r,1) == 1,
                content1 = content1 - 1
             end
             if A(r,1) == 2,
                content2 = content2 - 1
             end
             if A(r,1) == 3,
                content3 = content3 - 1
             end
        end
        r=r+1
    end
    t=t+1 %setze t um einen hoch
        B(t,1)=t-1 %schreibe erst nach erhöhung von t um 1 da ansonsten zu Beginn Reihe 0 wäre
        B(t,2)=content
        B(t,3)=content1
        B(t,4)=content2
        B(t,5)=content3
    
end
stairs(B(:,1),B(:,2)) %show content time graph


%area (0,50) 

%alternativ
%x=1:64  %hier muss dann eingesetzt werden, bis wo der Graph gezeigt werden
%soll

%for k=1:length(x)
    %result(k)= sum(A(:,2)<=x(k) & A(:,3)>=x(k))
%end
%figure
%stairs(x,result) 

% sum(B(1:end-1,2)) %Funktion bis zum Summieren bis zum Ende der ersten
% Spalte

