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

initial commit to HG from Changeset: 646 (e263d8a21543) added further path and more save "camirversion.m"
author Daniel Wolff
date Fri, 19 Aug 2016 13:07:06 +0200
parents
children
rev   line source
Daniel@0 1 function combis = param_combinations(params, pos)
Daniel@0 2 % given a param struct with multiple options for diverse
Daniel@0 3 % parameters, param_combinations(params) returns all
Daniel@0 4 % valid combinations of the param sets
Daniel@0 5
Daniel@0 6 if nargin < 2
Daniel@0 7 pos = 1;
Daniel@0 8 end
Daniel@0 9
Daniel@0 10 % get available fields
Daniel@0 11 fields = fieldnames(params);
Daniel@0 12
Daniel@0 13 nparams = params;
Daniel@0 14 if pos <= numel(fields)
Daniel@0 15
Daniel@0 16 for j = 1:numel(params.(fields{pos}))
Daniel@0 17
Daniel@0 18 % ---
Daniel@0 19 % successively ralter the params struct,
Daniel@0 20 % choosing one of the options
Daniel@0 21 % ---
Daniel@0 22 if ~iscell(params.(fields{pos}))
Daniel@0 23
Daniel@0 24 nparams.(fields{pos}) = params.(fields{pos})(j);
Daniel@0 25 else
Daniel@0 26
Daniel@0 27 nparams.(fields{pos}) = params.(fields{pos}){j};
Daniel@0 28 end
Daniel@0 29
Daniel@0 30 if j == 1
Daniel@0 31 combis = param_combinations(nparams, pos + 1);
Daniel@0 32
Daniel@0 33 else
Daniel@0 34
Daniel@0 35 % gather the resulting configurations, in reverse order
Daniel@0 36 % regarding the recursion
Daniel@0 37 combis = cat(1, param_combinations(nparams, pos + 1), combis);
Daniel@0 38 end
Daniel@0 39 end
Daniel@0 40 else
Daniel@0 41 % we have reached the leaves, containing single combinations
Daniel@0 42 combis = nparams;
Daniel@0 43 end
Daniel@0 44 end