Home > functions > internal > dsDataField2Table.m

dsDataField2Table

PURPOSE ^

Converts DynaSim structure to 1D cell array format. Later can use to

SYNOPSIS ^

function [data_table,column_titles] = dsDataField2Table (data,fieldname,verbose_flag)

DESCRIPTION ^

 Converts DynaSim structure to 1D cell array format. Later can use to
 import to MDD. In this case, pulls out a specific field from data,
 along with the varied information.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [data_table,column_titles] = dsDataField2Table (data,fieldname,verbose_flag)
0002     % Converts DynaSim structure to 1D cell array format. Later can use to
0003     % import to MDD. In this case, pulls out a specific field from data,
0004     % along with the varied information.
0005 
0006     if nargin < 3
0007         verbose_flag = 0;
0008     end
0009     
0010     % Create dummy varied variable if none there
0011     for i = 1:length(data)
0012         if ~isfield(data(i),'varied')
0013             data(i).varied = [];
0014         end
0015         if isempty(data(i).varied)
0016             data(i).varied = {'Varied1'};  % Random name for varied data
0017             data(i).Varied1 = i;           % Random value
0018         end
0019     end
0020     
0021     % ## VARIED parameter sweeps ##
0022     varied=data(1).varied;
0023     num_varied=length(varied); % number of model components varied across simulations
0024     num_sims=length(data); % number of data sets (one per simulation)
0025     %param_mat=zeros(num_sims,num_varied); % values for each simulation
0026     
0027     for j=1:num_varied
0028         if isnumeric(data(1).(varied{j}))
0029             params{j} = [data.(varied{j})]; % values for each simulation
0030         else
0031             for i = 1:length(data)
0032                 params{j}{i} = data(i).(varied{j});    %vals for each sim
0033             end
0034         end
0035     end
0036     
0037     % ## Build a large linear list ##
0038     z=0;
0039     num_alllabels = 1;
0040     for i = 1:num_sims
0041         for k = 1:num_alllabels
0042             
0043             z=z+1;
0044             data_linear{z} = data(i).(fieldname);
0045             
0046             % Number of parameter sweeps, plus populations, plus variables (Vm, state variables, functions, etc.)
0047             for j = 1:num_varied
0048                 if isnumeric(data(1).(varied{j})); ax{j}(z) = params{j}(i);
0049                 else
0050                     ax{j}{z} = params{j}{i};
0051                 end
0052             end
0053         end
0054     end
0055     
0056     ax_names = varied;
0057     
0058     
0059     % Transpose everything to make it in terms of columns instead of rows.
0060     data_linear = data_linear(:);
0061     for i = 1:length(ax)
0062         ax{i} = ax{i}';
0063     end
0064     
0065     % Combine everything into one data table
0066     data_table = horzcat({data_linear},ax);
0067     
0068     % List table column names
0069     column_titles = {'data',ax_names{:}};
0070     
0071     if verbose_flag
0072         previewTable(data_table,column_titles);
0073     end
0074     
0075 end

Generated on Tue 12-Dec-2017 11:32:10 by m2html © 2005