annotate core/tools/param_combinations.m @ 0:e9a9cd732c1e tip

first hg version after svn
author wolffd
date Tue, 10 Feb 2015 15:05:51 +0000
parents
children
rev   line source
wolffd@0 1 function combis = param_combinations(params, pos)
wolffd@0 2 % given a param struct with multiple options for diverse
wolffd@0 3 % parameters, param_combinations(params) returns all
wolffd@0 4 % valid combinations of the param sets
wolffd@0 5
wolffd@0 6 if nargin < 2
wolffd@0 7 pos = 1;
wolffd@0 8 end
wolffd@0 9
wolffd@0 10 % get available fields
wolffd@0 11 fields = fieldnames(params);
wolffd@0 12
wolffd@0 13 nparams = params;
wolffd@0 14 if pos <= numel(fields)
wolffd@0 15
wolffd@0 16 for j = 1:numel(params.(fields{pos}))
wolffd@0 17
wolffd@0 18 % ---
wolffd@0 19 % successively ralter the params struct,
wolffd@0 20 % choosing one of the options
wolffd@0 21 % ---
wolffd@0 22 if ~iscell(params.(fields{pos}))
wolffd@0 23
wolffd@0 24 nparams.(fields{pos}) = params.(fields{pos})(j);
wolffd@0 25 else
wolffd@0 26
wolffd@0 27 nparams.(fields{pos}) = params.(fields{pos}){j};
wolffd@0 28 end
wolffd@0 29
wolffd@0 30 if j == 1
wolffd@0 31 combis = param_combinations(nparams, pos + 1);
wolffd@0 32
wolffd@0 33 else
wolffd@0 34
wolffd@0 35 % gather the resulting configurations, in reverse order
wolffd@0 36 % regarding the recursion
wolffd@0 37 combis = cat(1, param_combinations(nparams, pos + 1), combis);
wolffd@0 38 end
wolffd@0 39 end
wolffd@0 40 else
wolffd@0 41 % we have reached the leaves, containing single combinations
wolffd@0 42 combis = nparams;
wolffd@0 43 end
wolffd@0 44 end