0001 function newstruct = ensemble_tree2datastruct(generic_struct,params)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 if(all(ismember({'name','type','vars','data'},fieldnames(generic_struct))))
0016 newstruct = generic_struct;
0017 return
0018 end
0019
0020 fnames = fieldnames(generic_struct);
0021
0022 typeIdx = strmatch('type',fnames,'exact');
0023 nameIdx = strmatch('name',fnames,'exact');
0024 newstruct = ensemble_init_data_struct;
0025
0026
0027
0028
0029 if(~isempty(typeIdx))
0030 fnames = setdiff(fnames,fnames{typeIdx});
0031 newstruct.type = generic_struct(1).type;
0032 end
0033
0034 if(~isempty(nameIdx))
0035 fnames = setdiff(fnames,fnames{nameIdx});
0036 newstruct.name = generic_struct(1).name;
0037 end
0038
0039 newstruct.vars = fnames';
0040
0041 for ifld = 1:length(fnames)
0042
0043 fieldType = '';
0044 struct_idx = 1;
0045
0046
0047 while(isempty(fieldType) & struct_idx <= length(generic_struct))
0048 dataCell = generic_struct(struct_idx).(fnames{ifld});
0049 if(~isempty(dataCell))
0050 if(isnumeric(dataCell) & (length(dataCell(:)) == 1))
0051 fieldType = 'numeric';
0052 elseif(isnumeric(dataCell) & (length(dataCell(:)) > 1))
0053 fieldType = 'matrix';
0054 elseif(isstruct(dataCell))
0055 fieldType = 'struct';
0056 elseif(ischar(dataCell))
0057 fieldType = 'char';
0058 elseif(iscell(dataCell))
0059 fieldType = 'cell';
0060 end
0061 end
0062 struct_idx = struct_idx + 1;
0063 end
0064
0065
0066 if(isempty(fieldType))
0067 fieldType = 'cell';
0068 end
0069
0070 for struct_idx = 1:length(generic_struct)
0071
0072 dataCell = generic_struct(struct_idx).(fnames{ifld});
0073
0074 switch fieldType
0075
0076 case 'numeric'
0077 if(isempty(dataCell))
0078 assignData = NaN;
0079 else
0080 assignData = dataCell;
0081 end
0082
0083 case 'struct'
0084 if(isempty(dataCell))
0085 assignData = {ensemble_init_data_struct};
0086 else
0087 assignData = {ensemble_tree2datastruct(dataCell)};
0088 end
0089
0090 case 'char'
0091 if(isempty(dataCell))
0092 assignData = {''};
0093 else
0094 assignData = {dataCell};
0095 end
0096
0097 case {'cell','matrix'}
0098 if(isempty(dataCell))
0099 assignData = {[]};
0100 else
0101 assignData = {dataCell};
0102 end
0103
0104 end
0105
0106 newstruct.data{1,ifld}(struct_idx,1) = assignData;
0107
0108 end
0109
0110
0111
0112 end
0113