Home > functions > internal > dsImportCSV.m

dsImportCSV

PURPOSE ^

IMPORTCSV - load CSV data into DynaSim formatted data structure.

SYNOPSIS ^

function data = dsImportCSV(file)

DESCRIPTION ^

IMPORTCSV - load CSV data into DynaSim formatted data structure.

 Usage:
   data=dsImportCSV(csvfile)

 Inputs:
   - datafile: CSV file organized according to output from dsWriteDynaSimSolver

 Outputs:
   - DynaSim data structure:
     data.(state_variables)
     data.(monitors)
     data.time
     data.simulator_options

 Note:
   - CSV file structure assumes CSV file contains data organized according to
   output from dsWriteDynaSimSolver: time points along rows; state variables and
   monitors are columns; first column is time vector; next columns are state
   variables; final columns are monitors. first row has headers for each
   column. if a population has more than one cell, different cells are
   sequential columns with same header repeated for each cell.

 See also: dsImport

 Author: Jason Sherfey, PhD <jssherfey@gmail.com>
 Copyright (C) 2016 Jason Sherfey, Boston University, USA

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function data = dsImportCSV(file)
0002 %IMPORTCSV - load CSV data into DynaSim formatted data structure.
0003 %
0004 % Usage:
0005 %   data=dsImportCSV(csvfile)
0006 %
0007 % Inputs:
0008 %   - datafile: CSV file organized according to output from dsWriteDynaSimSolver
0009 %
0010 % Outputs:
0011 %   - DynaSim data structure:
0012 %     data.(state_variables)
0013 %     data.(monitors)
0014 %     data.time
0015 %     data.simulator_options
0016 %
0017 % Note:
0018 %   - CSV file structure assumes CSV file contains data organized according to
0019 %   output from dsWriteDynaSimSolver: time points along rows; state variables and
0020 %   monitors are columns; first column is time vector; next columns are state
0021 %   variables; final columns are monitors. first row has headers for each
0022 %   column. if a population has more than one cell, different cells are
0023 %   sequential columns with same header repeated for each cell.
0024 %
0025 % See also: dsImport
0026 %
0027 % Author: Jason Sherfey, PhD <jssherfey@gmail.com>
0028 % Copyright (C) 2016 Jason Sherfey, Boston University, USA
0029 
0030 % check inputs
0031 if ~exist(file,'file')
0032   error('file not found.');
0033 end
0034 
0035 % load data
0036 contents=importdata(file,',');
0037 fields=unique_wrapper(contents.colheaders,'stable');
0038 data.labels=fields([2:length(fields) 1]); % move time vector to end of labels
0039 for i=1:length(fields)
0040   data.(fields{i})=contents.data(:,ismember(contents.colheaders,fields{i}));
0041 end
0042 data.datafile=file;

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