Home > bml > sync > bml_crop_idx_valid.m

bml_crop_idx_valid

PURPOSE ^

BML_CROP_IDX_VALID calculates valid sample indices for a time window and file coordinates

SYNOPSIS ^

function [starts_idx,ends_idx] = bml_crop_idx_valid(cfg, varargin)

DESCRIPTION ^

 BML_CROP_IDX_VALID calculates valid sample indices for a time window and file coordinates

 Same as BML_CROP_IDX but bounds the starts and ends sample to the 1 and
 nSample if necesarry

 Use as 
   [starts_idx,ends_idx] = bml_crop_idx_valid(cfg)
   [starts_idx,ends_idx] = bml_crop_idx_valid(cfg, starts, ends)
   [starts_idx,ends_idx] = bml_crop_idx_valid(cfg, starts, [], samples)
   [starts_idx,ends_idx] = bml_crop_idx_valid(cfg, [], ends, samples)

 where cfg is a configuration structure or roi table row
 cfg.starts
 cfg.ends
 (cfg.samples)
 cfg.t1
 cfg.s1
 cfg.t2
 cfg.s2
 cfg.nSamples - double: total number of samples in file
 cfg.tol - double: tolerance. Defaults to 1e-3/Fs. 

 if starts and ends are given (3 argument call) the values of cfg are
 ignored

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [starts_idx,ends_idx] = bml_crop_idx_valid(cfg, varargin)
0002 
0003 % BML_CROP_IDX_VALID calculates valid sample indices for a time window and file coordinates
0004 %
0005 % Same as BML_CROP_IDX but bounds the starts and ends sample to the 1 and
0006 % nSample if necesarry
0007 %
0008 % Use as
0009 %   [starts_idx,ends_idx] = bml_crop_idx_valid(cfg)
0010 %   [starts_idx,ends_idx] = bml_crop_idx_valid(cfg, starts, ends)
0011 %   [starts_idx,ends_idx] = bml_crop_idx_valid(cfg, starts, [], samples)
0012 %   [starts_idx,ends_idx] = bml_crop_idx_valid(cfg, [], ends, samples)
0013 %
0014 % where cfg is a configuration structure or roi table row
0015 % cfg.starts
0016 % cfg.ends
0017 % (cfg.samples)
0018 % cfg.t1
0019 % cfg.s1
0020 % cfg.t2
0021 % cfg.s2
0022 % cfg.nSamples - double: total number of samples in file
0023 % cfg.tol - double: tolerance. Defaults to 1e-3/Fs.
0024 %
0025 % if starts and ends are given (3 argument call) the values of cfg are
0026 % ignored
0027 
0028 
0029 nSamples  = bml_getopt(cfg,'nSamples',[]);
0030 assert(~isempty(nSamples),'cfg.nSamples required');
0031 
0032 [starts_idx,ends_idx] = bml_crop_idx(cfg, varargin{:});
0033 
0034 % bounding to begging and end of file
0035 if starts_idx<1
0036   starts_idx=1;
0037 elseif starts_idx>nSamples
0038    error('starts index exceeds number of samples in file');
0039 end
0040 if ends_idx>nSamples
0041   ends_idx=nSamples;
0042 elseif ends_idx<=0
0043   error('ends index %i before first sample',ends_idx);
0044 end

Generated on Tue 25-Sep-2018 10:08:19 by m2html © 2005