load eeg data from multiple files and concatenate them [data, channel_info, cond_id] = vb_load_active_trial_data(fileinfo) --- Input 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 activeChannel)] 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 data : concatenated data data [Nch x Nsample x Nactive] cond_id : condition number for each trials [1 x Nactive] channel_info : <<struct>> channel information of loaded data : .Active [Nchannel x 1] : .Name [Nchannel x 1] : .Type [Nchannel x 1] : .ID [Nchannel x 1] Masa-aki Sato 2009-8-4 2010-11-15 (Sako) modified loading data of each file MEG --> ALL 2011-03-01 (Sako) supported empty channel_id (return empty data) 2011-08-26 (Sako) modified for minimum format file Copyright (C) 2011, ATR All Rights Reserved. License : New BSD License(see VBMEG_LICENSE.txt)
0001 function [data, channel_info, cond_id] = vb_load_active_trial_data(fileinfo) 0002 % load eeg data from multiple files and concatenate them 0003 % 0004 % [data, channel_info, cond_id] = vb_load_active_trial_data(fileinfo) 0005 % 0006 % --- Input 0007 % fileinfo : structure with file information for multiple files 0008 % fileinfo.filename{n} : n-th session data file names [n=1:Nsession] 0009 % fileinfo.Nchannel : # of total channels 0010 % fileinfo.channel_id : active channel id [1 x (# of activeChannel)] 0011 % fileinfo.Nsample : # of samples in one trial 0012 % fileinfo.Ntotal : # of all trials 0013 % fileinfo.Ntrial : # of trials for each session [1 x Nsession] 0014 % fileinfo.session_id : session index for each trial [1 x Ntotal] 0015 % fileinfo.cond_id : condition number for each trials [1 x Ntotal] 0016 % - The above fields have info. for all trials in multiple epoch files 0017 % - following fields are active trial info. 0018 % fileinfo.act_trial : active trial index among all trials [1 x Nactive] 0019 % fileinfo.err_trial : error trial index [1 x Nerror] 0020 % 0021 % --- Output 0022 % data : concatenated data data [Nch x Nsample x Nactive] 0023 % cond_id : condition number for each trials [1 x Nactive] 0024 % channel_info : <<struct>> channel information of loaded data 0025 % : .Active [Nchannel x 1] 0026 % : .Name [Nchannel x 1] 0027 % : .Type [Nchannel x 1] 0028 % : .ID [Nchannel x 1] 0029 % 0030 % Masa-aki Sato 2009-8-4 0031 % 2010-11-15 (Sako) modified loading data of each file MEG --> ALL 0032 % 2011-03-01 (Sako) supported empty channel_id (return empty data) 0033 % 2011-08-26 (Sako) modified for minimum format file 0034 % 0035 % Copyright (C) 2011, ATR All Rights Reserved. 0036 % License : New BSD License(see VBMEG_LICENSE.txt) 0037 0038 filename = fileinfo.filename ; 0039 0040 Nsample = fileinfo.Nsample; 0041 Nchannel = fileinfo.Nchannel; 0042 Ntotal = fileinfo.Ntotal; 0043 0044 % Number of files 0045 Nfile = length(filename); 0046 0047 % active channel & trials 0048 act_trial = fileinfo.act_trial ; 0049 channel_id = fileinfo.channel_id; 0050 0051 if isempty(channel_id) 0052 warning('(%s) channel_id is empty\n', mfilename); 0053 data = []; 0054 channel_info = []; 0055 cond_id = []; 0056 return; 0057 end 0058 0059 % --- get the name list of target channel 0060 ch_info = vb_load_channel_info(filename{1}, 'USER', channel_id); 0061 ch_names = ch_info.Name; 0062 0063 % Number of active channel & trials 0064 Nch = length(channel_id); 0065 Nall = length(act_trial); 0066 0067 fprintf('Number of files to read: %d\n',Nfile) 0068 fprintf('Number of all trials: %d\n',Ntotal) 0069 fprintf('Number of all channels: %d\n',Nchannel) 0070 fprintf('Number of trials to read: %d\n',Nall) 0071 fprintf('Number of channels to read: %d\n',Nch) 0072 0073 data = zeros(Nch,Nsample,Ntotal); 0074 Nst = 0; 0075 0076 channel_info = []; 0077 0078 % Merge multiple data files 0079 for n=1:Nfile 0080 [measurement, device] = vb_load_device(filename{n}); 0081 0082 Measurement = upper(measurement); 0083 Device = upper(device); 0084 0085 % Load MEG/EEG data 0086 if (strcmp(Measurement, 'MEG') ... 0087 && (~strcmp(Device, 'YOKOGAWA') && ~strcmp(Device, 'BASIC')))... 0088 || (strcmp(Measurement, 'EEG') ... 0089 && (~strcmp(Device, 'BIOSEMI') && ~strcmp(Device, 'BASIC'))) 0090 [tmp_data] = vb_load_meg_data(filename{n}); 0091 0092 else 0093 0094 loadspec.ChannelName = ch_names; 0095 0096 if n == 1 0097 % one channel_info is enough 0098 [tmp_data ,channel_info] = vb_load_meg_data(filename{n}, loadspec); 0099 else 0100 [tmp_data] = vb_load_meg_data(filename{n}, loadspec); 0101 end 0102 end 0103 0104 Nc = size(tmp_data,1); 0105 Nt = size(tmp_data,3); 0106 ix = (1:Nt) + Nst; % consecutive index for concatenated data 0107 0108 data(:,:,ix) = tmp_data(:,:,:); 0109 0110 Nst = Nt + Nst; 0111 end 0112 0113 data = data(:,:,act_trial); 0114 return 0115