Home > vbmeg > functions > device > acqdata > vb_posfile_remake_eegfile.m

vb_posfile_remake_eegfile

PURPOSE ^

remake EEG-MAT file by loading posfile

SYNOPSIS ^

function [result] = vb_posfile_remake_eegfile(pos_file, eeg_file, new_file)

DESCRIPTION ^

 remake EEG-MAT file by loading posfile
 [usage]
   [result] = vb_posfile_remake_eegfile(pos_file, eeg_file, new_file)
 [input]
   pos_file : <required> <<file>> POS-MAT file
   eeg_file : <required> <<file>> EEG-MAT file
   new_file : <optional> new file name if you want [(update eeg_file)]
 [output]
     result : result code
            :  0) no problem
            : >1) something wrong
            :      1) bad pos_file
            :      2) bad eeg_file
 [note]
   
 [history]
   2009-08-05 (Sako) initial version
   2011-06-01 (Sako) modified according to the new data format

 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:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function [result] = vb_posfile_remake_eegfile(pos_file, eeg_file, new_file)
0002 % remake EEG-MAT file by loading posfile
0003 % [usage]
0004 %   [result] = vb_posfile_remake_eegfile(pos_file, eeg_file, new_file)
0005 % [input]
0006 %   pos_file : <required> <<file>> POS-MAT file
0007 %   eeg_file : <required> <<file>> EEG-MAT file
0008 %   new_file : <optional> new file name if you want [(update eeg_file)]
0009 % [output]
0010 %     result : result code
0011 %            :  0) no problem
0012 %            : >1) something wrong
0013 %            :      1) bad pos_file
0014 %            :      2) bad eeg_file
0015 % [note]
0016 %
0017 % [history]
0018 %   2009-08-05 (Sako) initial version
0019 %   2011-06-01 (Sako) modified according to the new data format
0020 %
0021 % Copyright (C) 2011, ATR All Rights Reserved.
0022 % License : New BSD License(see VBMEG_LICENSE.txt)
0023 
0024 % --- CHECK ARGUMENTS --- %
0025 if ~exist('pos_file', 'var'), pos_file = ''; end
0026 if ~exist('eeg_file', 'var'), eeg_file = ''; end
0027 if ~exist('new_file', 'var'), new_file = ''; end
0028 [pos_file, eeg_file, new_file, result] = ...
0029   inner_check_arguments(pos_file, eeg_file, new_file);
0030 
0031 if result ~= 0
0032   return;
0033 end
0034 
0035 % --- MAIN PROCEDURE --------------------------------------------------------- %
0036 %
0037 cur_eeg = load(eeg_file);
0038 
0039 pos_info = vb_posfile_get_posinfo(pos_file);
0040 % --- POS_INFO ------------------------------------
0041 %     SensorPosition: [96x3 double]
0042 %          CoordType: 'SPM_Right_m'
0043 %       ChannelLabel: {96x1 cell}
0044 %            Vcenter: [1 x 3]
0045 %            Vradius: [x1]
0046 % -------------------------------------------------
0047 
0048 eeg_info = vb_load_measurement_info(eeg_file);
0049 
0050 
0051 [eeg_idx, pos_idx] = ...
0052   vb_util_get_index(eeg_info.ChannelName, pos_info.ChannelLabel);
0053 
0054 % --- EEG channels
0055 n_channel = length(eeg_idx);
0056 
0057 old_ch_name = {};
0058 new_ch_name = {};
0059 if isfield(eeg_info, 'ChannelName')
0060   old_ch_name = eeg_info.ChannelName;
0061   new_ch_name = old_ch_name(eeg_idx);
0062 
0063   eeg_info.ChannelName = new_ch_name;
0064 end
0065 
0066 old_ch_id = [];
0067 new_ch_id = [];
0068 if isfield(eeg_info, 'ChannelID')
0069   old_ch_id = eeg_info.ChannelID;
0070   new_ch_id = old_ch_id(eeg_idx);
0071   eeg_info.ChannelID   = new_ch_id;
0072 end
0073 
0074 if isfield(eeg_info, 'ChannelInfo')
0075   ch_info.Active = eeg_info.ChannelInfo.Active(eeg_idx);
0076   ch_info.Name   = eeg_info.ChannelInfo.Name  (eeg_idx);
0077   ch_info.ID     = eeg_info.ChannelInfo.ID    (eeg_idx);
0078   ch_info.Type   = eeg_info.ChannelInfo.Type  (eeg_idx);
0079   
0080   eeg_info.ChannelInfo = ch_info;
0081 end
0082 
0083 if isfield(eeg_info, 'ActiveChannel')
0084   active_channel = eeg_info.ActiveChannel(eeg_idx);
0085   
0086   eeg_info.ActiveChannel = active_channel;
0087 end
0088 
0089 % --- EXTRA channels
0090 if isfield(eeg_info, 'ExtraChannelInfo')
0091   [ex_names, ex_idx] = vb_util_omit_list(old_ch_name, new_ch_name);
0092   
0093   if ~isempty(ex_names)
0094     ex_names = vb_util_arrange_list(ex_names, 0);
0095 
0096     n_ex_channel = length(ex_names);
0097     ex_info.Channel_active = ones(n_ex_channel,1);
0098     ex_info.Channel_name   = ex_names;
0099     ex_info.Channel_type   = ones(n_ex_channel,1);
0100     ex_info.Channel_id     = old_ch_id(ex_idx);
0101   
0102     % --- set to new eeg_info
0103     eeg_info.ExtraChannelInfo = ex_info;
0104   else
0105     fprintf('(%s) It may not be necessary to update ExtraChannelInfo\n', ...
0106       mfilename);
0107   end
0108 end
0109 
0110 
0111 % --- coordinates
0112 eeg_info = ...
0113   vb_eeginfo_set_sensor_position(eeg_info, pos_info.SensorPosition(pos_idx,:));
0114 
0115 % --- spherical
0116 [center, radius, c_type] = vb_posfile_get_sphericalinfo(pos_file);
0117 eeg_info.Vcenter   = center;
0118 eeg_info.Vradius   = radius;
0119 eeg_info.CoordType = c_type;
0120 
0121 % --- MRI_ID, TransInfo
0122 eeg_info.MRI_ID = vb_posfile_load_mrikey(pos_file);
0123 eeg_info = vb_info_set_transinfo(eeg_info, vb_posfile_load_transinfo(pos_file));
0124 
0125 % --- Nchannel
0126 eeg_info.Nchannel = n_channel;
0127 
0128 cur_eeg.EEGinfo = eeg_info;
0129 
0130 vb_save_struct(new_file, cur_eeg);
0131 return;
0132 %
0133 % --- END OF MAIN PROCEDURE -------------------------------------------------- %
0134 
0135 % --- INNER FUNCTIONS -------------------------------------------------------- %
0136 %
0137 % --- inner_check_arguments()
0138 %
0139 function [pos_file, eeg_file, new_file, result] = ...
0140   inner_check_arguments(pos_file, eeg_file, new_file)
0141 
0142 func_ = mfilename;
0143 result = 0;
0144 
0145 if isempty(pos_file)
0146   fprintf('(%s) pos_file is a required parameter\n', func_);
0147   result = 1;
0148   return;
0149 end
0150 
0151 if exist(pos_file, 'file') ~= 2
0152   fprintf('(%s) cannot find pos_file : %s\n', func_, pos_file);
0153   result = 1;
0154   return;
0155 end
0156 
0157 if isempty(eeg_file)
0158   fprintf('(%s) eeg_file is a required parameter\n', func_);
0159   result = 2;
0160   return;
0161 end
0162 
0163 if exist(eeg_file, 'file') ~= 2
0164   fprintf('(%s) cannot find eeg_file : %s\n', func_, eeg_file);
0165   result = 2;
0166   return;
0167 end
0168 
0169 if isempty(new_file)
0170   new_file = eeg_file;
0171 end
0172 return;
0173 %
0174 % --- end of inner_check_arguments()
0175 %
0176 % --- END OF INNER FUNCTIONS ------------------------------------------------- %
0177 
0178 % --- END OF FILE --- %

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