Home > vbmeg > functions > device > active_check > vb_get_active_cond.m

vb_get_active_cond

PURPOSE ^

Get active trial index with given conditions and sessions

SYNOPSIS ^

function fileinfo = vb_get_active_cond(fileinfo,cond_list,session_no)

DESCRIPTION ^

  Get active trial index with given conditions and sessions
   fileinfo = vb_get_active_cond(fileinfo,cond_list,session_no)
 --- Input
 cond_list  : list of condition to select
              if empty, all conditions are selected
 session_no : session number to select
              if empty, all sessions are selected
 fileinfo : structure with file information for multiple files
 fileinfo.filename{n}  : n-th session data file names [n=1:Nsession]
 fileinfo.Nchannel     : # of total channels
 fileinfo.channel_id   : active channel id [1 x (# of acticeChannel)]
 fileinfo.Nsample      : # of samples in one trial
 fileinfo.Ntotal       : # of all trials 
 fileinfo.Ntrial       : # of trials for each session [1 x Nsession]
 fileinfo.session_id   : session index for each trial [1 x Ntotal]
 fileinfo.cond_id      : condition number for each trials [1 x Ntotal]
  - The above fields have info. for all trials in multiple epoch files
  - following fields are active trial info.
 fileinfo.act_trial    : active trial index among all trials [1 x Nactive]
 --- Output (fields changed from input)
 Select active trials with given conditions and sessions
 fileinfo.act_trial    : active trial index  [1 x Nactive]
 fileinfo.cond_list  : selected condition numbers
 fileinfo.session_no : selected session numbers

 Masa-aki Sato 2008-8-10
 Masa-aki Sato 2009-1-31 ver.2

 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    fileinfo = vb_get_active_cond(fileinfo,cond_list,session_no)
0002 %  Get active trial index with given conditions and sessions
0003 %   fileinfo = vb_get_active_cond(fileinfo,cond_list,session_no)
0004 % --- Input
0005 % cond_list  : list of condition to select
0006 %              if empty, all conditions are selected
0007 % session_no : session number to select
0008 %              if empty, all sessions are selected
0009 % fileinfo : structure with file information for multiple files
0010 % fileinfo.filename{n}  : n-th session data file names [n=1:Nsession]
0011 % fileinfo.Nchannel     : # of total channels
0012 % fileinfo.channel_id   : active channel id [1 x (# of acticeChannel)]
0013 % fileinfo.Nsample      : # of samples in one trial
0014 % fileinfo.Ntotal       : # of all trials
0015 % fileinfo.Ntrial       : # of trials for each session [1 x Nsession]
0016 % fileinfo.session_id   : session index for each trial [1 x Ntotal]
0017 % fileinfo.cond_id      : condition number for each trials [1 x Ntotal]
0018 %  - The above fields have info. for all trials in multiple epoch files
0019 %  - following fields are active trial info.
0020 % fileinfo.act_trial    : active trial index among all trials [1 x Nactive]
0021 % --- Output (fields changed from input)
0022 % Select active trials with given conditions and sessions
0023 % fileinfo.act_trial    : active trial index  [1 x Nactive]
0024 % fileinfo.cond_list  : selected condition numbers
0025 % fileinfo.session_no : selected session numbers
0026 %
0027 % Masa-aki Sato 2008-8-10
0028 % Masa-aki Sato 2009-1-31 ver.2
0029 %
0030 % Copyright (C) 2011, ATR All Rights Reserved.
0031 % License : New BSD License(see VBMEG_LICENSE.txt)
0032 
0033 if nargin < 2, cond_list  = [];end
0034 if nargin < 3, session_no = [];end
0035 
0036 % If no condition is given, return
0037 if isempty(cond_list) && isempty(session_no), return; end;
0038 
0039 % Number of session
0040 Nsession = length(fileinfo.filename);
0041 
0042 if isempty(cond_list)
0043     cond_list = 1:max(fileinfo.cond_id);
0044 end
0045 if isempty(session_no)
0046     session_no = 1:Nsession;
0047 end
0048 
0049 Ntotal = fileinfo.Ntotal;
0050 Ncond  = length(cond_list);
0051 
0052 % --- Set selected condition flag
0053 cond_flg = zeros(1,Ntotal);
0054 
0055 for n=1:Ncond
0056     ix = find( fileinfo.cond_id == cond_list(n));
0057     cond_flg(ix) = 1;
0058 end
0059 
0060 % --- Set selected session flag
0061 session_flg = zeros(1,Ntotal);
0062 
0063 for n = session_no
0064     ix = find( fileinfo.session_id == n );
0065     session_flg(ix) = 1;
0066 end
0067 
0068 % --- Set active trial flag
0069 act_flg = zeros(1,Ntotal);
0070 if isfield(fileinfo, 'act_trial')
0071     act_flg(fileinfo.act_trial) = 1;
0072 else
0073     act_flg = fileinfo.ActiveTrial;
0074 end
0075 
0076 % --- Take AND of condition & session & active trial
0077 act_flg = (cond_flg .* session_flg .* act_flg);
0078 
0079 if isfield(fileinfo, 'act_trial')
0080     act_trial = find( act_flg > 0 );
0081     fileinfo.act_trial = act_trial;
0082 else
0083     fileinfo.ActiveTrial = act_flg;
0084 end
0085 fileinfo.cond_list = cond_list;
0086 fileinfo.session_no = session_no;

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