]> Creatis software - CreaPhase.git/blob - octave_packages/statistics-1.1.3/fullfact.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / statistics-1.1.3 / fullfact.m
1 ## Author: Paul Kienzle <pkienzle@users.sf.net>
2 ## This program is granted to the public domain.
3
4 ## -*- texinfo -*-
5 ## @deftypefn {Function File} fullfact (@var{N})
6 ## Full factorial design.
7 ##
8 ## If @var{N} is a scalar, return the full factorial design with @var{N} binary
9 ## choices, 0 and 1.
10 ##
11 ## If @var{N} is a vector, return the full factorial design with choices 1 
12 ## through @var{n_i} for each factor @var{i}.
13 ##
14 ## @end deftypefn
15
16 function A = fullfact(n)
17   if length(n) == 1
18     % combinatorial design with n either/or choices
19     A = fullfact(2*ones(1,n))-1;
20   else
21     % combinatorial design with n(i) choices per level
22     A = [1:n(end)]';
23     for i=length(n)-1:-1:1
24       A = [kron([1:n(i)]',ones(rows(A),1)), repmat(A,n(i),1)];
25     end
26   end
27 endfunction