function [OA,OV] = overlap(X,GZ,NCC,NCA,dA) % This routine takes as its central argument the matrix % GZ. This has one column for each animal whose home range % was computed by some other method and one row for each % point in the x,y sample grid. The values in GZ for any % column are the probabilities that the animal represented % by that column would be found at that grid point. The % matrix X has as many columns as the number of animals being % compared. Each column is filled with 0's except for the row % corresponding to the column in GZ that is to be included: % this cell has a 1 in it. The matrix NCC % contains one more column than the number of % animals considered. The first column contains the % of the % total home range volume sought. The subsequent values in the % same row give the minimal probability for the animal in that % column that contribute to the % cutoff in the first column of % NCC. The matrix NCA has the same first column, but gives the % area at each cutoff for each animal.The value dA is the area/cell % of the grid. The results are two matrices. The first column of each % reproduces the first column in NCC. The second column of OA gives the % area of overlap for the given contrast at the given cutoff. The % subsequent columns give the % of that cutoff area represented by the % overlap area for each animal. The output matrix OV has as first % column the cutoff %. The subsequent columns give the total probability % of finding each animal in that overlap zone. % Jack Bradbury, Cornell University, December 2000. GZZ=GZ*X; % reduce GZ matrix to those columns being compared [n,m]=size(GZZ); % Get new size of reduced matrix [r,p]=size(NCC); NC=NCC(:,2:p)*X; % Reduce NCA and NCC matrices accordingly NA=NCA(:,2:p)*X; OA=[]; OV=[]; [g,h]=size(NC); for i=1:g DC=repmat(NC(i,:),n,1); DD=GZZ-DC; for j=1:m if (~isempty(DD)) [MM,id]=find(DD(:,j)>=0); DD=DD(MM,:); end end if (~isempty(DD)) [k,l]=size(DD); DC=repmat(NC(i,:),k,1); DD=DD+DC; SA=k*dA; % Compute area of overlap zone OA=[OA;SA 100*(SA)./NA(i,:)]; % Store fraction of each animal area in overlap VA=100*sum(DD,1); % Get % volume of each animal in overlap OV=[OV;VA]; else w=zeros(1,(m+1)); OA=[OA;w]; v=zeros(1,m); OV=[OV;v]; end end OV=[NCC(:,1) OV]; OA=[NCC(:,1) OA];