Home > data-analysis > manip > cont > cont_extract_ranges.m

cont_extract_ranges

PURPOSE ^

Extract ranges of data from continuous or cstream data

SYNOPSIS ^

function [ sections ] = cont_extract_ranges( var_data, ranges )

DESCRIPTION ^

Extract ranges of data from continuous or cstream data
   cont_extract_ranges(DATA, RANGES)
       Goes through each range in RANGES.  For each range, finds the chunk
       of data in DATA that is within that range, extracts that chunk, and
       returns the list of chunks as a cell array.
       
   DATA should be a continuous or cstream variable.  It should be an nx2
   matrix, with one row per sample.  Each row is formatted [timestamp
   value].  This function also supports cont2, cont3, and so on: these
   formats don't work in the visualization program, but work with many of
   the matlab scripts.  They are an NxD matrix, with the columns D
   consisting of one timestamp and several values.  The function also
   supports cstreams, which have an identical storage format to cont
   variables.

   RANGES should be another nx2 or nx3 matrix (actually, any values
   after the first two are ignored).  Each row is a time range,
   formatted [begin_time end_time].  This is the same format as an
   event variable or a list of experimental trials, so you could pass
   one of those in unmodified.  All data points that have time stamps
   such that range_start <= timestamp < range_end will be included in
   the results.

   The return value is a vertical cell array, and the contents of each
   cell is a section of DATA.  If there is no data in some range, the
   corresponding cell of the return array will contain an empty matrix
   (though the empty matrix might not equal []).

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [ sections ] = cont_extract_ranges( var_data, ranges )
0002 %Extract ranges of data from continuous or cstream data
0003 %   cont_extract_ranges(DATA, RANGES)
0004 %       Goes through each range in RANGES.  For each range, finds the chunk
0005 %       of data in DATA that is within that range, extracts that chunk, and
0006 %       returns the list of chunks as a cell array.
0007 %
0008 %   DATA should be a continuous or cstream variable.  It should be an nx2
0009 %   matrix, with one row per sample.  Each row is formatted [timestamp
0010 %   value].  This function also supports cont2, cont3, and so on: these
0011 %   formats don't work in the visualization program, but work with many of
0012 %   the matlab scripts.  They are an NxD matrix, with the columns D
0013 %   consisting of one timestamp and several values.  The function also
0014 %   supports cstreams, which have an identical storage format to cont
0015 %   variables.
0016 %
0017 %   RANGES should be another nx2 or nx3 matrix (actually, any values
0018 %   after the first two are ignored).  Each row is a time range,
0019 %   formatted [begin_time end_time].  This is the same format as an
0020 %   event variable or a list of experimental trials, so you could pass
0021 %   one of those in unmodified.  All data points that have time stamps
0022 %   such that range_start <= timestamp < range_end will be included in
0023 %   the results.
0024 %
0025 %   The return value is a vertical cell array, and the contents of each
0026 %   cell is a section of DATA.  If there is no data in some range, the
0027 %   corresponding cell of the return array will contain an empty matrix
0028 %   (though the empty matrix might not equal []).
0029 %
0030 
0031 % create a cell array with as many rows as there are ranges
0032 sections = cell(size(ranges, 1), 1);
0033 
0034 float_tolerance = 1e-12;
0035 
0036 if isempty(var_data)
0037     sections = {};
0038     return
0039 end
0040 
0041 for range_idx = 1:size(ranges, 1)
0042 
0043     range = ranges(range_idx, :); %range(1) is start, range(2) is end.
0044     
0045     % These two arrays are logical indicies for var_data.
0046     ge_start = range(1) <= var_data(:, 1) + float_tolerance;
0047     lt_end = var_data(:, 1) + float_tolerance < range(2);
0048     
0049     sections{range_idx} = var_data(ge_start & lt_end, :);
0050 end
0051 
0052 
0053 
0054 
0055 end
0056

Generated on Tue 23-May-2017 20:00:55 by m2html © 2005