Daniel@0: function combis = param_combinations(params, pos) Daniel@0: % given a param struct with multiple options for diverse Daniel@0: % parameters, param_combinations(params) returns all Daniel@0: % valid combinations of the param sets Daniel@0: Daniel@0: if nargin < 2 Daniel@0: pos = 1; Daniel@0: end Daniel@0: Daniel@0: % get available fields Daniel@0: fields = fieldnames(params); Daniel@0: Daniel@0: nparams = params; Daniel@0: if pos <= numel(fields) Daniel@0: Daniel@0: for j = 1:numel(params.(fields{pos})) Daniel@0: Daniel@0: % --- Daniel@0: % successively ralter the params struct, Daniel@0: % choosing one of the options Daniel@0: % --- Daniel@0: if ~iscell(params.(fields{pos})) Daniel@0: Daniel@0: nparams.(fields{pos}) = params.(fields{pos})(j); Daniel@0: else Daniel@0: Daniel@0: nparams.(fields{pos}) = params.(fields{pos}){j}; Daniel@0: end Daniel@0: Daniel@0: if j == 1 Daniel@0: combis = param_combinations(nparams, pos + 1); Daniel@0: Daniel@0: else Daniel@0: Daniel@0: % gather the resulting configurations, in reverse order Daniel@0: % regarding the recursion Daniel@0: combis = cat(1, param_combinations(nparams, pos + 1), combis); Daniel@0: end Daniel@0: end Daniel@0: else Daniel@0: % we have reached the leaves, containing single combinations Daniel@0: combis = nparams; Daniel@0: end Daniel@0: end