function [datamatrix_cb,datamatrix_eu,corr_cb_eu,gamma_cb_eu,datavectors,coord, ...
    coord_mds_cb,stress_cb,coord_mds_eu,stress_eu,outpermone_cb,outpermtwo_cb, ...
    vaf_cb,outpermone_eu,outpermtwo_eu,vaf_eu] ...
    = data_generate(n,error,elongation_factor)

rand('state', sum(100*clock));

coord = rand(n,2);
coord(:,1) = coord(:,1)*elongation_factor;
datavectors = zeros(n*(n-1)/2,2);
datamatrix_cb = zeros(n,n);
datamatrix_eu = zeros(n,n);

for i = 1:(n-1)
    for j = (i+1):n
        
        datamatrix_cb(i,j) = abs(coord(i,1) - coord(j,1)) + ...
            abs(coord(i,2) - coord(j,2));
        
        datamatrix_eu(i,j) = sqrt(((coord(i,1) - coord(j,1))^2) + ...
            ((coord(i,2) - coord(j,2))^2));
        
        datamatrix_cb(j,i) = datamatrix_cb(i,j);
        datamatrix_eu(j,i) = datamatrix_eu(i,j);
        
    end
end

[randprox_cb] = proxrand(datamatrix_cb);
[randprox_eu] = proxrand(datamatrix_eu);

datamatrix_cb = datamatrix_cb + (error*randprox_cb);
datamatrix_eu = datamatrix_eu + (error*randprox_eu);

index = 0;

sumsqone = 0.0;
sumsqtwo = 0.0;

for i = 1:(n-1)
    for j = (i+1):n
        
        index = index + 1;
        
        datavectors(index,1) = datamatrix_cb(i,j);
        datavectors(index,2) = datamatrix_eu(i,j);
        
        sumsqone = sumsqone + datavectors(index,1)^2;
        sumsqtwo = sumsqtwo + datavectors(index,2)^2;
        
        
    end
end

%datavectors(:,1) = datavectors(:,1)*(1/sqrt(sumsqone));
%datavectors(:,2) = datavectors(:,2)*(1/sqrt(sumsqtwo));


corr_cb_eu = corrcoef(datavectors);

length_vector = n*(n-1)/2;
splus = 0.0;
sminus = 0.0;

for i = 1:(length_vector - 1)
    for j = (i+1):length_vector
        
        signfunction = (datavectors(i,1) - datavectors(j,1))* ...
            (datavectors(i,2) - datavectors(j,2));
        
        if(signfunction > 0.0)
            
            splus = splus + 1;
            
        end
        
        if(signfunction < 0.0)
            
            sminus = sminus + 1;
            
        end
    end
end

gamma_cb_eu = (splus - sminus)/(splus+sminus);

[coord_mds_cb, stress_cb] = mdscale(datamatrix_cb,2,'Start','random','Criterion','metricstress');

[coord_mds_eu, stress_eu] = mdscale(datamatrix_eu,2,'Start','random','Criterion','metricstress');

[outpermone_cb,outpermtwo_cb,coordone,coordtwo,fitone,fittwo, ...
    addconone,addcontwo,vaf_cb] = ...
biscalqa(datamatrix_cb,targlin(n),targlin(n),randperm(n),randperm(n),2,1);


[outpermone_eu,outpermtwo_eu,coordone,coordtwo,fitone,fittwo, ...
    addconone,addcontwo,vaf_eu] = ...
biscalqa(datamatrix_eu,targlin(n),targlin(n),randperm(n),randperm(n),2,1);



