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] fileinfo.err_trial : error trial index [1 x Nerror] --- 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)
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 % fileinfo.err_trial : error trial index [1 x Nerror] 0022 % --- Output (fields changed from input) 0023 % Select active trials with given conditions and sessions 0024 % fileinfo.act_trial : active trial index [1 x Nactive] 0025 % fileinfo.cond_list : selected condition numbers 0026 % fileinfo.session_no : selected session numbers 0027 % 0028 % Masa-aki Sato 2008-8-10 0029 % Masa-aki Sato 2009-1-31 ver.2 0030 % 0031 % Copyright (C) 2011, ATR All Rights Reserved. 0032 % License : New BSD License(see VBMEG_LICENSE.txt) 0033 0034 if nargin < 2, cond_list = [];end 0035 if nargin < 3, session_no = [];end 0036 0037 % If no condition is given, return 0038 if isempty(cond_list) && isempty(session_no), return; end; 0039 0040 % Number of session 0041 Nsession = length(fileinfo.filename); 0042 0043 if isempty(cond_list) 0044 cond_list = 1:max(fileinfo.cond_id); 0045 end 0046 if isempty(session_no) 0047 session_no = 1:Nsession; 0048 end 0049 0050 Ntotal = fileinfo.Ntotal; 0051 Ncond = length(cond_list); 0052 0053 % --- Set selected condition flag 0054 cond_flg = zeros(1,Ntotal); 0055 0056 for n=1:Ncond 0057 ix = find( fileinfo.cond_id == cond_list(n)); 0058 cond_flg(ix) = 1; 0059 end 0060 0061 % --- Set selected session flag 0062 session_flg = zeros(1,Ntotal); 0063 0064 for n = session_no 0065 ix = find( fileinfo.session_id == n ); 0066 session_flg(ix) = 1; 0067 end 0068 0069 % --- Set active trial flag 0070 act_flg = zeros(1,Ntotal); 0071 act_flg(fileinfo.act_trial) = 1; 0072 % --- Take AND of condition & session & active trial 0073 act_flg = (cond_flg .* session_flg .* act_flg); 0074 0075 act_trial = find( act_flg > 0 ); 0076 0077 fileinfo.act_trial = act_trial; 0078 fileinfo.cond_list = cond_list; 0079 fileinfo.session_no = session_no;