2 % Creates the cartesian product of the vectors passed as a
3 % matrix containing elements of each vector per row.
6 % ranges: Can either be a cell array of vectors or a vector.
7 % varargin: If the first argument is a vector, an arbitrary
8 % number of additional vectors can be passed to build the
9 % cartesian product from.
12 % comb: A matrix containing the combinations, each row
13 % corresponds to an input vector
's range.
15 % this file was taken from KerMor
16 % @author Daniel Wirtz @date 11.10.2010
18 if ~isa(ranges,'cell
')
23 r = cell(1,length(varargin)+1);
25 [r{2:end}] = varargin{:};
31 [matrices{1:n}] = ndgrid(ranges{:});
32 % Convert to np x params matrix
33 comb = zeros(n,numel(matrices{1}));
35 % Check if any range is empty - return empty then
36 if isempty(matrices{idx})
41 comb(idx,:) = matrices{idx}(:);
function comb = createCombinations(ranges, varargin)
Creates the cartesian product of the vectors passed as a matrix containing elements of each vector pe...