Home > functions > internal > dsRearrangeStudies2Neurons.m

dsRearrangeStudies2Neurons

PURPOSE ^

REARRANGESTUDIES2NEURONS - Takes a DynaSim data structure that is the result of a parameter sweep and rearranges it into a single (1D) data structure.

SYNOPSIS ^

function data_out = dsRearrangeStudies2Neurons(data)

DESCRIPTION ^

REARRANGESTUDIES2NEURONS - Takes a DynaSim data structure that is the result of a parameter sweep and rearranges it into a single (1D) data structure.

 Each "neuron" in this new data structure corresponds to a simulation in the
 original sim study.

 If there is more than one cell in a population, each trace will represent the 
 averaged activity across neurons.

 This is useful when you want to run multiple simulations and see how 
 the averaged responses of populations vary. It is also useful when running
 the same simulation multiple times (with different) seed values and then
 observing the variance across these sims.

 Usage:
   data_out = RearrangeStudies2Cells(data,'option',value)

 Inputs:
   - data: DynaSim data structure array (see dsCheckData). Length(data) should
           be greater than 1.

 Outputs:
   - data_out: data structure of length 1.

 Example:
   data = RearrangeStudies2Cells(data)
   dsPlot(data)

 See also: dsCalcAverages, dsAnalyzeStudy, dsSimulate, dsCheckData, dsSelectVariables

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function data_out = dsRearrangeStudies2Neurons(data)
0002 %REARRANGESTUDIES2NEURONS - Takes a DynaSim data structure that is the result of a parameter sweep and rearranges it into a single (1D) data structure.
0003 %
0004 % Each "neuron" in this new data structure corresponds to a simulation in the
0005 % original sim study.
0006 %
0007 % If there is more than one cell in a population, each trace will represent the
0008 % averaged activity across neurons.
0009 %
0010 % This is useful when you want to run multiple simulations and see how
0011 % the averaged responses of populations vary. It is also useful when running
0012 % the same simulation multiple times (with different) seed values and then
0013 % observing the variance across these sims.
0014 %
0015 % Usage:
0016 %   data_out = RearrangeStudies2Cells(data,'option',value)
0017 %
0018 % Inputs:
0019 %   - data: DynaSim data structure array (see dsCheckData). Length(data) should
0020 %           be greater than 1.
0021 %
0022 % Outputs:
0023 %   - data_out: data structure of length 1.
0024 %
0025 % Example:
0026 %   data = RearrangeStudies2Cells(data)
0027 %   dsPlot(data)
0028 %
0029 % See also: dsCalcAverages, dsAnalyzeStudy, dsSimulate, dsCheckData, dsSelectVariables
0030 
0031 %% 1.0 Check inputs
0032 
0033 data = dsCheckData(data, varargin{:});
0034 % note: calling dsCheckData() at beginning enables analysis function to
0035 % accept data matrix [time x cells] in addition to DynaSim data structure.
0036 
0037 %% Average all cells together if necessary
0038 
0039 data = dsCalcAverages(data, varargin{:});
0040 
0041 %% Compress data structure array into a single structure
0042 
0043 
0044 % Identify all fields in data containing simulated output
0045 labels = data(1).labels;
0046 labels = labels(~strcmp(labels,'time'));
0047 
0048 
0049 % Initialize data_out
0050 data_out.labels = data(1).labels;
0051 data_out.model = data(1).model;
0052 data_out.simulator_options = data(1).simulator_options;
0053 if isfield(data(1),'time')
0054     data_out.time = data(1).time;
0055 end
0056 
0057 % Initialize other fields to empty matrices.
0058 for j = 1:length(labels)
0059     data_out.(labels{j}) = [];
0060 end
0061 
0062 % Move the averages from data into data_out
0063 for i = 1:length(data)
0064     for j = 1:length(labels)
0065         % Add ith simulation result for as a new neuron for label(j);
0066         data_out(1).(labels{j}) = cat(2,data_out(1).(labels{j}), data(i).(labels{j}));      
0067     end
0068     
0069 end
0070 
0071 % Update number of cells in each population to correspond to the total number of
0072 % sims in the original SimStudy parameter sweep
0073 for i = 1:length(data_out.model.specification.populations)
0074     data_out.model.specification.populations(i).size = length(data);
0075 end
0076 
0077 
0078 
0079 
0080 
0081 end

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