function N=perm(v1,v2,v3)

%% Permutes the numbers in vector v into K bins %%%

%function N=perm(v,K);

%n = length(v);
 
% pre allocate matrix
%m = zeros(n^K,K);
 
% calculate temporary number sequence
%c = repmat(v(:),n^(K-1),1);
 
% scan columns
% t is a temporary variable
%for col = 1:K,
%    t = reshape(c,n^col,length(c)/(n^col));
%    t = t';
%    m(:,col) = t(:);
%end 

%N=m;



l3=length(v3);
l2=length(v2)*l3;
l1=length(v1)*l2;

m=zeros(l1,3);

c=repmat(v1,l2,1);
m(:,1)=c(:);

c=repmat(v2,l3,1);
c=c(:);
c=repmat(c,length(v1),1);
m(:,2)=c;

c=v3.';
c=repmat(c,length(v2)*length(v1),1);
m(:,3)=c;

N=m;

