0001 function [data_table,column_titles,time] = dsData2Table(data,verbose_flag,maxrows)
0002
0003
0004
0005 if nargin < 2
0006 verbose_flag = 0;
0007 end
0008
0009 if nargin < 3
0010 maxrows = 10;
0011 end
0012
0013 dsCheckData(data);
0014
0015
0016 time = data(1).time;
0017
0018
0019 for i = 1:length(data)
0020 if ~isfield(data(i),'varied')
0021 data(i).varied = [];
0022 end
0023 if isempty(data(i).varied)
0024 data(i).varied = {'Varied1'};
0025 data(i).Varied1 = i;
0026 end
0027 end
0028
0029
0030 varied=data(1).varied;
0031 num_varied=length(varied);
0032 num_sims=length(data);
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050 labels = data(1).labels;
0051 labels = labels(cellfun(@isempty,strfind(labels,'time')));
0052 num_labels = length(labels);
0053
0054
0055 pop_names={data(1).model.specification.populations.name};
0056
0057
0058 separatorInds = strfind(labels,'_');
0059 func1 = @(x,y) x(1:y(1)-1);
0060 func2 = @(x,y) x(y(1)+1:end);
0061 pops = cellfun(func1,labels,separatorInds,'UniformOutput',0);
0062 vars = cellfun(func2,labels,separatorInds,'UniformOutput',0);
0063
0064
0065 ind=0;
0066 data_linear = cell(1,num_sims*num_labels);
0067 for iSim = 1:num_sims
0068 for iLabel = 1:num_labels
0069
0070 ind=ind+1;
0071 data_linear{ind} = data(iSim).(labels{iLabel});
0072
0073
0074 for iVar = 1:num_varied
0075 if isnumeric(data(1).(varied{iVar}))
0076
0077 ax{iVar}(ind) = data(iSim).(varied{iVar});
0078 else
0079
0080 ax{iVar}{ind} = data(iSim).(varied{iVar});
0081 end
0082 end
0083
0084 ax{num_varied+1}{ind} = pops{iLabel};
0085
0086
0087 ax{num_varied+2}{ind} = vars{iLabel};
0088
0089 end
0090 end
0091
0092 ax_names = varied;
0093 ax_names{num_varied+1} = 'populations';
0094 ax_names{num_varied+2} = 'variables';
0095
0096
0097 data_linear = data_linear(:);
0098 for i = 1:length(ax)
0099 ax{i} = ax{i}';
0100 end
0101
0102
0103 data_table = horzcat({data_linear},ax);
0104
0105
0106 column_titles = {'data',ax_names{:}};
0107
0108 if verbose_flag
0109 previewTable(data_table,column_titles,maxrows);
0110 end
0111
0112 end