0001 function xp = ds2mdd(data,merge_covaried_axes,merge_sparse_axes,varargin)
0002
0003
0004 data = dsCheckData(data, varargin{:});
0005
0006 if nargin < 2
0007 merge_covaried_axes = true;
0008 end
0009
0010 if nargin < 3
0011 merge_sparse_axes = true;
0012 end
0013
0014
0015
0016 if merge_covaried_axes && isfield(data(1),'varied')
0017
0018
0019 labels = data(1).labels;
0020 inds = arrayfun(@(s) ~isempty(s.(labels{1})),data);
0021 data = data(inds);
0022
0023
0024
0025
0026 [Abasis,Abasisi, Asubs] = dsGetLinearIndependentDs(data);
0027
0028 gt1 = cellfun(@(x) length(x) > 1, Asubs);
0029 Asubs = Asubs(gt1);
0030
0031
0032
0033
0034 vary_labels = data(1).varied;
0035 Nlinked = length(Asubs);
0036 variedname_merged = cell(1,Nlinked);
0037 varied_vals = cell(1,Nlinked);
0038 for j = 1:Nlinked
0039 [data, variedname_merged{j}, varied_vals{j} ] = dsMergeVarieds(data,vary_labels(Asubs{j}));
0040 end
0041
0042
0043
0044
0045 end
0046
0047 if merge_sparse_axes && isfield(data(1),'varied')
0048 [data, variedname_merged, varied_vals ] = dsAutoMergeVarieds(data);
0049 end
0050
0051
0052
0053
0054 [data_table,column_titles,time] = dsData2Table (data);
0055
0056
0057
0058
0059
0060
0061
0062 xp = MDD;
0063 X = data_table{1};
0064 axislabels = data_table(2:end);
0065 xp = xp.importDataTable(X,axislabels);
0066 xp = xp.importAxisNames(column_titles(2:end));
0067
0068
0069 meta = struct;
0070 meta.datainfo(1:2) = MDDAxis;
0071 meta.datainfo(1).name = 'time(ms)';
0072 meta.datainfo(1).values = time;
0073 meta.datainfo(2).name = 'cells';
0074 cell_names = [1:max(cellfun(@(x) size(x,2),xp.data(:)))];
0075 cell_names_str = cellfunu(@(s) ['Cell ' num2str(s)], num2cell(cell_names));
0076 meta.datainfo(2).values = cell_names_str;
0077 meta.dynasim.labels = data(1).labels;
0078 meta.dynasim.model = data(1).model;
0079 meta.dynasim.simulator_options = data(1).simulator_options;
0080 meta.dynasim.time = data(1).time;
0081 if isfield(data(1),'varied')
0082 meta.dynasim.varied = data(1).varied;
0083 else
0084
0085 meta.dynasim.varied = {'Varied1'};
0086 end
0087 xp.meta = meta;
0088 clear meta
0089
0090
0091
0092 if merge_covaried_axes && isfield(data(1),'varied')
0093
0094
0095
0096
0097
0098
0099
0100
0101
0102
0103
0104 end
0105 end
0106
0107 function var2 = convert_cell2D_to_nested1D(var)
0108 for k = 1:size(var,2)
0109 var2{k} = cell2mat(var(:,k));
0110 end
0111 end