Home > vbmeg > functions > device > trigger_timing > vb_merge_multi_file_trial.m

vb_merge_multi_file_trial

PURPOSE ^

Merge trials of multiple files

SYNOPSIS ^

function vb_merge_multi_file_trial(fname, fout, cond_label)

DESCRIPTION ^

 Merge trials of multiple files
 --- Usage
    vb_merge_multi_file_trial(fname, fout)
    vb_merge_multi_file_trial(fname, fout, cond_label)
 --- Input
  fname : set of file name of trial onset [cell string]
  fname{i} : i-th trial onset file name   [ i=1:Nfile ]
  fout   : output file name of merged trials
 --- Optional Input
  cond_label(i) : condition label for fname{n} [ i=1:Nfile ]
 --- Save variables
 status : status signal
 status_val(m) = status value for m-th condition (m=1:Ncomdition)
 trig(n)       : Onset time index for n-th trial 
 cond_id(n)    : condition label for n-th trial 
 ix_trial(:,n) : Time index for n-th trial   [Tperiod x Ntrial]
                 Tperiod : # of time sample in one trial
                 Ntrial  : # of trials
 parm : parameter setting
  parm.fsamp : Sample Frequency [Hz]
  parm.Pretrigger_ms : Pretrigger period   [msec]
  parm.Posttrigger_ms: Posttrigger period  [msec]

 2009-6-14  Masa-aki Sato

 Copyright (C) 2011, ATR All Rights Reserved.
 License : New BSD License(see VBMEG_LICENSE.txt)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function    vb_merge_multi_file_trial(fname, fout, cond_label)
0002 % Merge trials of multiple files
0003 % --- Usage
0004 %    vb_merge_multi_file_trial(fname, fout)
0005 %    vb_merge_multi_file_trial(fname, fout, cond_label)
0006 % --- Input
0007 %  fname : set of file name of trial onset [cell string]
0008 %  fname{i} : i-th trial onset file name   [ i=1:Nfile ]
0009 %  fout   : output file name of merged trials
0010 % --- Optional Input
0011 %  cond_label(i) : condition label for fname{n} [ i=1:Nfile ]
0012 % --- Save variables
0013 % status : status signal
0014 % status_val(m) = status value for m-th condition (m=1:Ncomdition)
0015 % trig(n)       : Onset time index for n-th trial
0016 % cond_id(n)    : condition label for n-th trial
0017 % ix_trial(:,n) : Time index for n-th trial   [Tperiod x Ntrial]
0018 %                 Tperiod : # of time sample in one trial
0019 %                 Ntrial  : # of trials
0020 % parm : parameter setting
0021 %  parm.fsamp : Sample Frequency [Hz]
0022 %  parm.Pretrigger_ms : Pretrigger period   [msec]
0023 %  parm.Posttrigger_ms: Posttrigger period  [msec]
0024 %
0025 % 2009-6-14  Masa-aki Sato
0026 %
0027 % Copyright (C) 2011, ATR All Rights Reserved.
0028 % License : New BSD License(see VBMEG_LICENSE.txt)
0029 
0030 if ~iscell(fname), error('argument should be cell string');end
0031 
0032 Nfile = length(fname);
0033 if nargin < 3, cond_label = [1:Nfile]; end;
0034 
0035 load(fname{1},'ix_trial','trig','status','status_val','parm');
0036 
0037 fs = parm.fsamp;
0038 Tmax = size(status,2);
0039 [T, Ntr] = size(ix_trial);
0040 
0041 Ix_trial = ix_trial;
0042 Trig     = trig    ;
0043 Cond_id  = repmat(cond_label(1), 1, Ntr);
0044 Status_val = status_val;
0045 Condition  = parm.condition;
0046 
0047 % load trial
0048 for n = 2:Nfile
0049     load(fname{n},'ix_trial','trig','status','status_val','parm');
0050     
0051     if fs ~= parm.fsamp, error('Sample frequency mismatch'); end;
0052     if Tmax ~= size(status,2), error('Sample length mismatch'); end
0053     if T ~= size(ix_trial,1), error('Trial length mismatch'); end
0054 
0055     Ix_trial = [Ix_trial, ix_trial];
0056     Trig     = [Trig    , trig    ];
0057     Cond_id  = [Cond_id , repmat(cond_label(n), 1, length(trig))];
0058     Status_val = [Status_val, status_val];
0059     Condition  = cat(2,Condition,  parm.condition);
0060 end
0061 
0062 trig     = Trig    ;
0063 ix_trial = Ix_trial;
0064 cond_id  = Cond_id ;
0065 
0066 % sort time order
0067 [trig, ix] = sort(trig);
0068 ix_trial = ix_trial(:,ix);
0069 cond_id  = cond_id(ix) ;
0070 
0071 status_val     = Status_val;
0072 parm.condition = Condition ;
0073 
0074 fprintf('# of merge trials = %d\n',length(trig));
0075 
0076 vb_fsave(fout,'ix_trial','trig','cond_id','status','status_val','parm');

Generated on Mon 22-May-2023 06:53:56 by m2html © 2005