


BML_CROP returns a time-cropped raw [INTERNAL]
Use as
croped = bml_crop(raw, starts, ends)
croped = bml_crop(cfg, raw)
raw - FT_DATATYPE_RAW data to be cropped
starts - double array: time in seconds for begging of each trial
length of starts should coincide with number of trials of raw
ends - double array: time in seconds for the end of each trial
length of ends should coincide with number of trials of raw
This function was designed to crop continuous files and is mailny used as
an internal function. Use BML_REDEFINETRIAL to re-epoch a RAW.

0001 function cropped = bml_crop(raw, starts, ends) 0002 0003 % BML_CROP returns a time-cropped raw [INTERNAL] 0004 % 0005 % Use as 0006 % croped = bml_crop(raw, starts, ends) 0007 % croped = bml_crop(cfg, raw) 0008 % 0009 % raw - FT_DATATYPE_RAW data to be cropped 0010 % starts - double array: time in seconds for begging of each trial 0011 % length of starts should coincide with number of trials of raw 0012 % ends - double array: time in seconds for the end of each trial 0013 % length of ends should coincide with number of trials of raw 0014 % 0015 % This function was designed to crop continuous files and is mailny used as 0016 % an internal function. Use BML_REDEFINETRIAL to re-epoch a RAW. 0017 0018 if nargin==2 0019 cfg=raw; 0020 raw=starts; 0021 if istable(cfg) 0022 starts = cfg.starts; 0023 ends = cfg.ends; 0024 elseif isstruct(cfg) 0025 starts = bml_getopt(cfg,'starts'); 0026 ends = bml_getopt(cfg,'ends'); 0027 end 0028 elseif nargin~=3 0029 error('invalid use of bml_crop'); 0030 end 0031 0032 assert(length(starts)==numel(raw.trial),... 0033 "length of starts (%i) doesn't match number of trials (%i)",length(starts),numel(raw.trial)); 0034 assert(length(ends)==numel(raw.trial),... 0035 "length of ends (%i) doesn't match number of trials (%i)",length(ends),numel(raw.trial)); 0036 0037 cropped=raw; 0038 for i=1:numel(raw.trial) 0039 nSamples = length(raw.time{i}); 0040 0041 tc=bml_raw2coord(raw,i); 0042 [s,e]=bml_crop_idx(tc,starts(i),ends(i)); 0043 0044 if s < 1; s=1; end 0045 if e > nSamples; e = nSamples; end 0046 0047 cropped.trial{i} = raw.trial{i}(:,s:e); 0048 cropped.time{i} = raw.time{i}(:,s:e); 0049 cropped.sampleinfo(i,:) = [s,e]; 0050 end 0051