comparison 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
comparison
equal deleted inserted replaced
-1:000000000000 0:e9a9cd732c1e
1 function combis = param_combinations(params, pos)
2 % given a param struct with multiple options for diverse
3 % parameters, param_combinations(params) returns all
4 % valid combinations of the param sets
5
6 if nargin < 2
7 pos = 1;
8 end
9
10 % get available fields
11 fields = fieldnames(params);
12
13 nparams = params;
14 if pos <= numel(fields)
15
16 for j = 1:numel(params.(fields{pos}))
17
18 % ---
19 % successively ralter the params struct,
20 % choosing one of the options
21 % ---
22 if ~iscell(params.(fields{pos}))
23
24 nparams.(fields{pos}) = params.(fields{pos})(j);
25 else
26
27 nparams.(fields{pos}) = params.(fields{pos}){j};
28 end
29
30 if j == 1
31 combis = param_combinations(nparams, pos + 1);
32
33 else
34
35 % gather the resulting configurations, in reverse order
36 % regarding the recursion
37 combis = cat(1, param_combinations(nparams, pos + 1), combis);
38 end
39 end
40 else
41 % we have reached the leaves, containing single combinations
42 combis = nparams;
43 end
44 end