From f984be8d40e1d93b1b518830193f9bb8d1b42d55 Mon Sep 17 00:00:00 2001 From: Olivier Sauter <olivier.sauter@epfl.ch> Date: Thu, 17 Sep 2015 16:28:23 +0000 Subject: [PATCH] add and copy new gdat version git-svn-id: https://spcsvn.epfl.ch/repos/TCV/gdat/trunk@5024 d63d8f72-b253-0410-a779-e742ad2e26cf --- crpptbx/subcall_all2str.m | 59 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 crpptbx/subcall_all2str.m diff --git a/crpptbx/subcall_all2str.m b/crpptbx/subcall_all2str.m new file mode 100644 index 00000000..a87eff3a --- /dev/null +++ b/crpptbx/subcall_all2str.m @@ -0,0 +1,59 @@ +function subcall_string = subcall_all2str(varargin) +% +% subcall_string = subcall_all2str(varargin) +% +% create a string from varargin allowing following types: +% +% char: varargin is just copied +% numeric: if scalar use num2str, if 1 or 2-D array add relevant '[' and ']', else mark a string multi-D +% structure: explode structure as field,value +% + +% to be taken from above and include this call in above + +if nargin==0 + subcall_string = ''; + return +end + +subcall = ''; +for i_in=1:length(varargin) + var_to_treat = varargin{i_in}; + if isstruct(var_to_treat) + % explode structure into 'childname',childvalues + param_names = fieldnames(var_to_treat); + for i=1:length(param_names) + subcall = [subcall ',''' param_names{i} '''']; + if ischar(var_to_treat.(param_names{i})) + subcall = [subcall ',''' var_to_treat.(param_names{i}) '''']; + elseif isnumeric(var_to_treat.(param_names{i})) + aa_values = var_to_treat.(param_names{i}); + if prod(size(aa_values))~= length(aa_values) + % multi-D input, do not treat it yet + subcall = [subcall ',''multi-D input''']; + elseif length(aa_values) > 1 + % array + subcall = [subcall ',[' num2str(reshape(aa_values,1,length(aa_values))) ']']; + else + subcall = [subcall ',' num2str(aa_values) '']; + end + else + % to treat extra cases + end + end + elseif isnumeric(var_to_treat) + if prod(size(var_to_treat))~= length(var_to_treat) + % multi-D input, do not treat it yet + subcall = [subcall ',''multi-D input''']; + elseif length(var_to_treat) > 1 + % array + subcall = [subcall ',[' num2str(var_to_treat) ']']; + else + subcall = [subcall ',' num2str(var_to_treat) '']; + end + elseif ischar(var_to_treat) + subcall = [subcall ',''' var_to_treat '''']; + end +end + +subcall_string = subcall; -- GitLab