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

vb_get_multi_fileinfo

PURPOSE ^

Create Fileinfo-file which is to treat multiple MEG/EEG files as if

SYNOPSIS ^

function [fileinfo] = vb_get_multi_fileinfo(datafiles, outfile)

DESCRIPTION ^

 Create Fileinfo-file which is to treat multiple MEG/EEG files as if 
 single MEG/EEG file. 
 [Usage]
  [fileinfo] = vb_get_multi_fileinfo(datafiles, outfile);
 [Input]
  datafiles : cell array of multiple data file names.
              datafiles{n} : n-th file name  [n=1:Nsession]
  outfile   : output file name to save multiple file information 'fileinfo'
              if 'outfile' is not given, no output file is made
 [Output]
  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.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]
  fileinfo.ActiveChannel: Active channel list (boolean array) [Nchannel x 1]
  fileinfo.ActiveTrial  : Active trial list   (boolean array) [Ntotal x 1]

 [History]
   Masa-aki 2009-01-31
   Sako     2009-09-01 substituted vb_load_measurement_info for vb_load_meg_info
   Sako     2009-12-15 modified vb_load_measurement_info to return MEG format info
   rhayashi 2017-04-20 unified Active information between MEG(EEGinfo).Active and fileinfo.
                       (obsolete fields)channel_id, act_trial
                       (new fields)     ActiveChannel, ActiveTrial

 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_multi_fileinfo(datafiles, outfile)
0002 % Create Fileinfo-file which is to treat multiple MEG/EEG files as if
0003 % single MEG/EEG file.
0004 % [Usage]
0005 %  [fileinfo] = vb_get_multi_fileinfo(datafiles, outfile);
0006 % [Input]
0007 %  datafiles : cell array of multiple data file names.
0008 %              datafiles{n} : n-th file name  [n=1:Nsession]
0009 %  outfile   : output file name to save multiple file information 'fileinfo'
0010 %              if 'outfile' is not given, no output file is made
0011 % [Output]
0012 %  fileinfo  : structure with file information for multiple files
0013 %  fileinfo.filename{n}  : n-th session data file names [n=1:Nsession]
0014 %  fileinfo.Nchannel     : # of total channels
0015 %  fileinfo.Nsample      : # of samples in one trial
0016 %  fileinfo.Ntotal       : # of all trials
0017 %  fileinfo.Ntrial       : # of trials for each session [1 x Nsession]
0018 %  fileinfo.session_id   : session index for each trial [1 x Ntotal]
0019 %  fileinfo.cond_id      : condition number for each trials [1 x Ntotal]
0020 %  fileinfo.ActiveChannel: Active channel list (boolean array) [Nchannel x 1]
0021 %  fileinfo.ActiveTrial  : Active trial list   (boolean array) [Ntotal x 1]
0022 %
0023 % [History]
0024 %   Masa-aki 2009-01-31
0025 %   Sako     2009-09-01 substituted vb_load_measurement_info for vb_load_meg_info
0026 %   Sako     2009-12-15 modified vb_load_measurement_info to return MEG format info
0027 %   rhayashi 2017-04-20 unified Active information between MEG(EEGinfo).Active and fileinfo.
0028 %                       (obsolete fields)channel_id, act_trial
0029 %                       (new fields)     ActiveChannel, ActiveTrial
0030 %
0031 % Copyright (C) 2011, ATR All Rights Reserved.
0032 % License : New BSD License(see VBMEG_LICENSE.txt)
0033 
0034 if ~iscell(datafiles)
0035     tmp = datafiles;
0036     datafiles = {tmp};
0037 end;
0038 
0039 % Number of EEG file
0040 Nfile = length(datafiles);
0041 
0042 %% ---- EEGinfo ---- %%
0043 info     = vb_load_measurement_info(datafiles{1}, 'MEGINFO');
0044 fsamp    = info.SampleFreq;
0045 Nsample  = info.Nsample;
0046 Nchannel = info.Nchannel;
0047 
0048 % Trial number for each file
0049 Ntrial    = zeros(1,Nfile);
0050 trial_id  = cell(1,Nfile);
0051 cond_id = [];
0052 
0053 Nst = 0;
0054 
0055 for n=1:Nfile
0056     info = vb_load_measurement_info(datafiles{n}, 'MEGINFO');
0057     
0058     if fsamp ~= info.SampleFreq,
0059         error('SampleFrequency does not match');
0060     end
0061     if Nsample ~= info.Nsample,
0062         error('NSample does not match');
0063     end
0064 
0065     if Nchannel ~= info.Nchannel,
0066         error('Nchannel does not match');
0067     end
0068     
0069     Ntrial(n) = info.Nrepeat;
0070     ix_trial = (1:Ntrial(n)) + Nst;
0071     Nst = Ntrial(n) + Nst;
0072     
0073     trial_id{n}  = ix_trial;
0074     
0075     if isfield(info,'cond_id')
0076         cond_id = [cond_id, info.cond_id];
0077     else
0078         cond_id = [cond_id, ones(1,Ntrial(n))];
0079     end
0080 end
0081 
0082 Ntotal = sum(Ntrial);
0083 session_id = zeros(1,Ntotal);
0084 
0085 for n=1:Nfile
0086     session_id(trial_id{n}) = n;
0087 end
0088 
0089 fileinfo.filename  = datafiles;
0090 fileinfo.Ntotal    = Ntotal;
0091 fileinfo.Ntrial    = Ntrial;
0092 fileinfo.Nsample   = Nsample;
0093 fileinfo.Nchannel  = Nchannel;
0094 fileinfo.cond_id    = cond_id;
0095 fileinfo.session_id = session_id;
0096 
0097 % Active information
0098 fileinfo.ActiveChannel = ones(Nchannel, 1);
0099 fileinfo.ActiveTrial   = ones(Ntotal,   1);
0100 
0101 
0102 %% ---- info ---- %%
0103 
0104 if exist('outfile','var') && ~isempty(outfile)
0105     fprintf('Number of files: %d\n',Nfile)
0106     fprintf('Number of all trials: %d\n', Ntotal)
0107     fprintf('Save fileinfo: %s\n',outfile)
0108     
0109     Measurement = 'INFO';
0110     
0111     vb_fsave(outfile,'fileinfo','Measurement');
0112 end
0113 
0114 return

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