function os = consistent_struct(varargin) if(rem(length(varargin),2)) error("there must be even number of input arguments"); endif os = []; for struct_field_number = 1:2:length(varargin) #fprintf(stderr, "key: %s\n", varargin{struct_field_number}); key = varargin{struct_field_number}; # no check of 'key' correctness is performed val = varargin{struct_field_number + 1}; os = setfield(os, key, val); endfor endfunction # testcase for Yury T - assuming Yuri wants to access things by "file1*.dat" par1_1=1; par2_1=2; par1_2=3; par2_2=4; name = consistent_struct\ ( "file1.dat", {par1_1, par2_1, "ID1"}, "file2.dat", {par1_2, par2_2, "ID2"} ); getfield(name, "file2.dat"){1} getfield(name, "file2.dat"){1, 1} # pay attention - the above two lines produce the same output - 2 * crap !! getfield(name, "file2.dat"){2} getfield(name, "file2.dat"){1, 2} # pay attention - the above two lines produce the same output - 2 * crap !! getfield(name, "file2.dat"){3} getfield(name, "file2.dat"){1, 3} # pay attention - the above two lines produce the same output - 2 * crap !! name # pay attention - _two_ indices (like [1,2]) are printed - 2 * crap !!