Home > functions > internal > dsMdd2dsImage.m

dsMdd2dsImage

PURPOSE ^

% data=MDD2ds(obj,varargin)

SYNOPSIS ^

function data = MDD2dsImage(obj)

DESCRIPTION ^

% data=MDD2ds(obj,varargin)
 Dependencies:
   Requires the MDD class, which should be part of DynaSim. If not,
   get it here https://github.com/davestanley/MDD
 Author: David Stanley, Boston University, stanleyd@bu.edu

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function data = MDD2dsImage(obj)
0002 %% data=MDD2ds(obj,varargin)
0003 % Dependencies:
0004 %   Requires the MDD class, which should be part of DynaSim. If not,
0005 %   get it here https://github.com/davestanley/MDD
0006 % Author: David Stanley, Boston University, stanleyd@bu.edu
0007 
0008 % This combines the 2D "vary" sweep into a single dimension. It also
0009 % combines all populations and variables into a single 1D list. Thus, Axis
0010 % 1 is equivalent to Jason's structure array - data(1:9). Axis 4 is
0011 % equivalent to the structure fields in Jason's DynaSim structure.
0012 %
0013 % % % Testing code
0014 % load sample_data_dynasim.mat
0015 % data1=data;
0016 % data2 = data(1);
0017 % d1 = MDD2ds(ds2mdd(data1));
0018 % d2 = MDD2ds(ds2mdd(data2));
0019 % d2b = MDD2ds(squeeze(ds2mdd(data2)));
0020 % % Make sure 1 is identical
0021 % close all;
0022 % dsPlot(data1); dsPlot(d1);
0023 % % Make sure 2 is identical
0024 % dsPlot(data2); dsPlot(d2);
0025 % dsPlot(data2); dsPlot(d2b);
0026 
0027 % Squeeze out populations and variables axes (should remove them if they
0028 % are of size 1)
0029 obj = obj.squeezeRegexp('populations');
0030 obj = obj.squeezeRegexp('variables');
0031 
0032 % Find population and variable axes
0033 if ~isempty(obj.findaxis('populations')); error('Populations axis should be empty'); end
0034 if ~isempty(obj.findaxis('variables')); error('Variables axis should be empty'); end
0035 
0036 % Merge all varieds together
0037 obj = obj.mergeDims(1:ndims(obj));
0038 
0039 % Get rid of any leftover axes created by mergeDims
0040 obj = obj.squeezeRegexp('Dim');
0041 
0042 % Make sure the "varied" parameters are along dimension 2 (e.g. so it's
0043 % 1xNvaried)
0044 if iscolumn(obj.data); obj=obj.transpose; end
0045 
0046 % Build DynaSim data structure
0047 data = struct;
0048 ax_vals = obj.exportAxisVals;
0049 ax_names = obj.exportAxisNames;
0050 varied = obj.axis(2).axismeta.premerged_names;
0051 varied_vals = obj.axis(2).axismeta.premerged_values;
0052 has_varied = 1;
0053 
0054 for j = 1:size(obj,2)                               % Loop through varieds
0055     
0056     data(j).plot_files = obj.data{j};
0057     
0058     % If there are any varied parameters....
0059     if has_varied
0060         % Add list of varied variables
0061         data(j).varied = varied;
0062 
0063         % Add values of varied variables
0064         for i = 1:length(varied)
0065             if isnumeric(varied_vals{i}(j))
0066                 data(j).(varied{i}) = varied_vals{i}(j);
0067             else
0068                 data(j).(varied{i}) = varied_vals{i}{j};
0069             end
0070         end
0071     end
0072     
0073 end
0074 
0075 
0076 end

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