Robochameleon  v1.0
combvec.m
1 function y = combvec(varargin)
2 %COMBVEC Create all combinations of vectors.
3 %
4 % Syntax
5 %
6 % combvec(a1,a2,...)
7 %
8 % Description
9 %
10 % COMBVEC(A1,A2,...) takes any number of inputs,
11 % A1 - Matrix of N1 (column) vectors.
12 % A2 - Matrix of N2 (column) vectors.
13 % and returns a matrix of (N1*N2*...) column vectors, where the columns
14 % consist of all possibilities of A2 vectors, appended to
15 % A1 vectors, etc.
16 %
17 % Example
18 %
19 % a1 = [1 2 3; 4 5 6];
20 % a2 = [7 8; 9 10];
21 % a3 = combvec(a1,a2)
22 
23 % Mark Beale, 12-15-93
24 % Copyright 1992-2005 The MathWorks, Inc.
25 % $Revision: 1.1.6.2 $ $Date: 2005/12/22 18:19:12 $
26 
27 if length(varargin) == 0
28  y = [];
29 else
30  y = varargin{1};
31  for i=2:length(varargin)
32  z = varargin{i};
33  y = [copy_blocked(y,size(z,2)); copy_interleaved(z,size(y,2))];
34 end
35 end
36 
37 %=========================================================
38 function b = copy_blocked(m,n)
39 
40 [mr,mc] = size(m);
41 b = zeros(mr,mc*n);
42 ind = 1:mc;
43 for i=[0:(n-1)]*mc
44  b(:,ind+i) = m;
45 end
46 %=========================================================
47 
48 function b = copy_interleaved(m,n)
49 
50 [mr,mc] = size(m);
51 b = zeros(mr*n,mc);
52 ind = 1:mr;
53 for i=[0:(n-1)]*mr
54  b(ind+i,:) = m;
55 end
56 b = reshape(b,mr,n*mc);
function end(in obj, in k, in n)
Overload of indexing end statement.