Home > vbmeg > functions > device > vb_msrmnt_update_active_flag_ex.m

vb_msrmnt_update_active_flag_ex

PURPOSE ^

update active flags of extra channels and make new file if you want

SYNOPSIS ^

function vb_msrmnt_update_active_flag_ex(base_file, active_ch, new_file)

DESCRIPTION ^

 update active flags of extra channels and make new file if you want
 [usage]
   vb_msrmnt_update_active_flag_ex(base_file, active_ch, new_file)
 [input]
   base_file : <required> <<file>> base file (.meg.mat or .eeg.mat)
   active_ch : <optional> [Nchannel x 1 boolean] [[]]
             :  if this is given, MEG(EEG)info.ActiveChannel will be updated
    new_file : <optional> <<file>> new file name ['']
             :  if this is empty, base_file will be over-written
 [output]
   none
 [note]

 [history]
   2009-07-08 (Sako) initial version

 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 vb_msrmnt_update_active_flag_ex(base_file, active_ch, new_file)
0002 % update active flags of extra channels and make new file if you want
0003 % [usage]
0004 %   vb_msrmnt_update_active_flag_ex(base_file, active_ch, new_file)
0005 % [input]
0006 %   base_file : <required> <<file>> base file (.meg.mat or .eeg.mat)
0007 %   active_ch : <optional> [Nchannel x 1 boolean] [[]]
0008 %             :  if this is given, MEG(EEG)info.ActiveChannel will be updated
0009 %    new_file : <optional> <<file>> new file name ['']
0010 %             :  if this is empty, base_file will be over-written
0011 % [output]
0012 %   none
0013 % [note]
0014 %
0015 % [history]
0016 %   2009-07-08 (Sako) initial version
0017 %
0018 % Copyright (C) 2011, ATR All Rights Reserved.
0019 % License : New BSD License(see VBMEG_LICENSE.txt)
0020 
0021 % --- CHECK ARGUMENTS --- %
0022 if ~exist('base_file', 'var'), base_file = ''; end
0023 if ~exist('active_ch', 'var'), active_ch = []; end
0024 if ~exist('new_file',  'var'), new_file = '';  end
0025 [base_file, active_ch, new_file] = ...
0026   inner_check_arguments(base_file, active_ch, new_file);
0027 
0028 % --- MAIN PROCEDURE --------------------------------------------------------- %
0029 %
0030 info = vb_load_measurement_info(base_file);
0031 n_channel = vb_info_get_Nchannel(info);
0032 
0033 if ~isempty(active_ch)
0034   act_len = size(active_ch, 1);
0035   if act_len ~= n_channel
0036     warning('(%s)length of active_ch (%d) ~= n_channel(%d)\n', ...
0037       mfilename, act_len, n_channel);
0038     fprintf('(%s)ActiveChannel has not been updated\n', mfilename);
0039   else
0040     info = vb_info_set_active_channel(info, active_ch);
0041   end
0042 end
0043 
0044 if ~isempty(active_tr)
0045   act_len = size(active_tr, 1);
0046   if act_len ~= n_trial
0047     warning('(%s)length of active_tr (%d) ~= n_trial(%d)\n', ...
0048       mfilename, act_len, n_trial);
0049     fprintf('(%s)ActiveTrial has not been updated\n', mfilename);
0050   else
0051     info = vb_info_set_active_trial(info, active_tr);
0052   end
0053 end
0054 
0055 % --- make new file
0056 if ~isempty(new_file)
0057   org_data = load(base_file);
0058   measurement = vb_info_get_measurement(info);
0059   
0060   switch measurement
0061     case 'MEG'
0062       org_data.MEGinfo = info;
0063     case 'EEG'
0064       org_data.EEGinfo = info;
0065     otherwise
0066       error('(%s) unknown measurement : %s', mfilename, measurement);
0067   end
0068   
0069   vb_save_struct(new_file, org_data);
0070 end
0071 %
0072 % --- END OF MAIN PROCEDURE -------------------------------------------------- %
0073 
0074 % --- INNER FUNCTIONS -------------------------------------------------------- %
0075 %
0076 % --- inner_check_arguments()
0077 %
0078 function [base_file, active_ch, active_tr, new_file] = ...
0079   inner_check_arguments(base_file, active_ch, active_tr, new_file)
0080 func_ = mfilename;
0081 
0082 if isempty(base_file)
0083   error('(%s) base_file is a required parameter', func_);
0084 end
0085 
0086 if exist(base_file, 'file') ~= 2
0087   error('(%s) cannot find base_file : %s', func_, base_file);
0088 end
0089 
0090 if isempty(active_ch)
0091   % nothing to do
0092 end
0093 
0094 if isempty(active_tr)
0095   % nothing to do
0096 end
0097 
0098 if isempty(new_file)
0099   new_file = base_file;
0100 end
0101 return;
0102 %
0103 % --- end of inner_check_arguments()
0104 %
0105 % --- END OF INNER FUNCTIONS ------------------------------------------------- %
0106 
0107 %%% END OF FILE %%%

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