make list of start-end samples from LoadSpec [usage] [samples] = vb_loadspec_make_trial_sample(loadspec) [input] loadspec : <required> <<struct>> LoadSpec : .Trigger : [Ntrial x1 double] sample number list of trigger : .Pretrigger : [x1 double] number of sample before trigger : .Posttrigger : [x1 double] number of sample after trigger : .TrialNumber : [Ntrial x1 double] trial index list [output] samples : [Ntrial x 2] list of from-to : if trigger data in loadspec is invalid, return empty [note] [history] 2008-02-29 (Sako) initial version 2009-07-28 (Sako) modified to return empty if trigger data is invalid Copyright (C) 2011, ATR All Rights Reserved. License : New BSD License(see VBMEG_LICENSE.txt)
0001 function [samples] = vb_loadspec_make_trial_sample(loadspec) 0002 % make list of start-end samples from LoadSpec 0003 % [usage] 0004 % [samples] = vb_loadspec_make_trial_sample(loadspec) 0005 % [input] 0006 % loadspec : <required> <<struct>> LoadSpec 0007 % : .Trigger : [Ntrial x1 double] sample number list of trigger 0008 % : .Pretrigger : [x1 double] number of sample before trigger 0009 % : .Posttrigger : [x1 double] number of sample after trigger 0010 % : .TrialNumber : [Ntrial x1 double] trial index list 0011 % [output] 0012 % samples : [Ntrial x 2] list of from-to 0013 % : if trigger data in loadspec is invalid, return empty 0014 % [note] 0015 % 0016 % [history] 0017 % 2008-02-29 (Sako) initial version 0018 % 2009-07-28 (Sako) modified to return empty if trigger data is invalid 0019 % 0020 % Copyright (C) 2011, ATR All Rights Reserved. 0021 % License : New BSD License(see VBMEG_LICENSE.txt) 0022 0023 % --- CHECK ARGUMENTS --- % 0024 if ~exist('loadspec', 'var'), loadspec = []; end 0025 [trigger, pretrigger, posttrigger] = inner_check_arguments(loadspec); 0026 0027 % --- MAIN PROCEDURE --------------------------------------------------------- % 0028 % 0029 if isempty(trigger) || isempty(pretrigger) || isempty(posttrigger) 0030 samples = []; 0031 return; 0032 end 0033 0034 samples = [(trigger-pretrigger), (trigger+posttrigger)]; 0035 return 0036 % 0037 % --- END OF MAIN PROCEDURE -------------------------------------------------- % 0038 0039 % --- INNER FUNCTIONS -------------------------------------------------------- % 0040 % 0041 % --- inner_check_arguments() 0042 % 0043 function [trigger, pretrigger, posttrigger] = inner_check_arguments(loadspec) 0044 func_ = mfilename; 0045 0046 trigger = []; 0047 pretrigger = []; 0048 posttrigger = []; 0049 if isempty(loadspec) 0050 % fprintf('(%s)loadspec is a required parameter\n', func_); 0051 return; 0052 end 0053 0054 if ~isfield(loadspec, 'Trigger') || isempty(loadspec.Trigger) ... 0055 || ~isfield(loadspec, 'Pretrigger') || isempty(loadspec.Pretrigger) ... 0056 || ~isfield(loadspec, 'Posttrigger') || isempty(loadspec.Posttrigger) 0057 % fprintf('(%s)invalid trigger in loadspec\n', func_); 0058 return; 0059 end 0060 0061 trigger = vb_util_arrange_list(loadspec.Trigger); 0062 pretrigger = loadspec.Pretrigger; 0063 posttrigger = loadspec.Posttrigger; 0064 return; 0065 % 0066 % --- end of inner_check_arguments() 0067 % 0068 % --- END OF INNER FUNCTIONS ------------------------------------------------- % 0069 0070 %%% END OF FILE %%%