Home > vbmeg > functions > device > vb_msrmnt_update_active_flag.m

vb_msrmnt_update_active_flag

PURPOSE ^

update active flags and make new file if you want

SYNOPSIS ^

function vb_msrmnt_update_active_flag(base_file, active_ch, active_tr, new_file)

DESCRIPTION ^

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

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