Home > functions > internal > dsCalcAverages.m

dsCalcAverages

PURPOSE ^

CALCAVERAGES - Average fields in a DynaSim data struct across neurons

SYNOPSIS ^

function data_out = dsCalcAverages(data,opts, varargin)

DESCRIPTION ^

CALCAVERAGES - Average fields in a DynaSim data struct across neurons

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

 Inputs:
   - data: DynaSim data structure (see dsCheckData)
   - opts: Options structure
     'opts.save_std': Also creates new fields storing standard deviations
                      (true or false)

 Outputs:
   - data_out: data structure, all fields replaced by their average values
       (averaged across neurons).

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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function data_out = dsCalcAverages(data,opts, varargin)
0002 %CALCAVERAGES - Average fields in a DynaSim data struct across neurons
0003 %
0004 % Usage:
0005 %   data_out = dsCalcAverages(data,'option',value)
0006 %
0007 % Inputs:
0008 %   - data: DynaSim data structure (see dsCheckData)
0009 %   - opts: Options structure
0010 %     'opts.save_std': Also creates new fields storing standard deviations
0011 %                      (true or false)
0012 %
0013 % Outputs:
0014 %   - data_out: data structure, all fields replaced by their average values
0015 %       (averaged across neurons).
0016 %
0017 % See also: dsPlotFR, dsAnalyzeStudy, dsSimulate, dsCheckData, dsSelectVariables
0018 
0019 %% auto_gen_test_data_flag argin
0020 options = dsCheckOptions(varargin,{'auto_gen_test_data_flag',0,{0,1}},false);
0021 if options.auto_gen_test_data_flag
0022   varargs = varargin;
0023   varargs{find(strcmp(varargs, 'auto_gen_test_data_flag'))+1} = 0;
0024   varargs(end+1:end+2) = {'unit_test_flag',1};
0025   argin = [{data}, {opts}, varargs]; % specific to this function
0026 end
0027 
0028 %% 1.0 Check inputs
0029 if nargin < 2
0030     opts = struct;
0031 end
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 opts = struct_addDef(opts,'save_std',0);
0038 
0039 %% do the averaging
0040 
0041 data_out = data;
0042 for i = 1:length(data)
0043     % Identify all fields in data containing simulated output
0044     labels = data(i).labels;
0045     labels = labels(~strcmp(labels,'time'));
0046     
0047     % Sweep through these fields and take averages
0048     for j = 1:length(labels)
0049         % Save mean
0050         data_out(i).(labels{j}) = mean(data(i).(labels{j}),2);
0051         
0052         % Save standard deviation also if requested
0053         if opts.save_std
0054             data_out(i).([labels{j} '_std']) = std(data(i).(labels{j}),0,2);
0055         end
0056     end
0057     
0058     % Set the size of all populations to 1
0059     for j = 1:length(data(i).model.specification.populations)
0060         data_out(i).model.specification.populations(j).size = 1;
0061     end
0062     
0063 end
0064 
0065 %% auto_gen_test_data_flag argout
0066 if options.auto_gen_test_data_flag
0067   argout = {data_out}; % specific to this function
0068   
0069   dsUnitSaveAutoGenTestData(argin, argout);
0070 end
0071 
0072 end

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