Home > 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   save_cmd = sprintf('save -struct org_data %s', new_file);
0070   eval(save_cmd);
0071 end
0072 %
0073 % --- END OF MAIN PROCEDURE -------------------------------------------------- %
0074 
0075 % --- INNER FUNCTIONS -------------------------------------------------------- %
0076 %
0077 % --- inner_check_arguments()
0078 %
0079 function [base_file, active_ch, active_tr, new_file] = ...
0080   inner_check_arguments(base_file, active_ch, active_tr, new_file)
0081 func_ = mfilename;
0082 
0083 if isempty(base_file)
0084   error('(%s) base_file is a required parameter', func_);
0085 end
0086 
0087 if exist(base_file, 'file') ~= 2
0088   error('(%s) cannot find base_file : %s', func_, base_file);
0089 end
0090 
0091 if isempty(active_ch)
0092   % nothing to do
0093 end
0094 
0095 if isempty(active_tr)
0096   % nothing to do
0097 end
0098 
0099 if isempty(new_file)
0100   new_file = base_file;
0101 end
0102 return;
0103 %
0104 % --- end of inner_check_arguments()
0105 %
0106 % --- END OF INNER FUNCTIONS ------------------------------------------------- %
0107 
0108 %%% END OF FILE %%%

Generated on Tue 27-Aug-2013 11:46:04 by m2html © 2005