Home > vbmeg > functions > device > meg > vb_megfile_make_channel_info.m

vb_megfile_make_channel_info

PURPOSE ^

make ChannelInfo from channel label

SYNOPSIS ^

function channel_info = vb_megfile_make_channel_info(megfile,meg_labels, ext_labels, ref_labels)

DESCRIPTION ^

 make ChannelInfo from channel label

 [usage]
   channel_info = vb_megfile_make_channel_info(megfile, ...
      meg_labels, ext_labels, ref_labels)

 [input]
      megfile : <required> <<file>> MEG-MAT file
   meg_labels : <optional> MEG channel label list       {Nchannel_meg x 1}
   ext_labels : <optional> EXTRA channel label list     {Nchannel_ext x 1}
   ref_labels : <optional> REFERENCE channel label list {Nchannel_ref x 1}

 [output]
   channel_info : <<struct>>
                :  .Active [Nchannel x 1]
                :  .Name   {Nchannel x 1}
                :  .Type   [Nchannel x 1]
                :  .ID     [Nchannel x 1]
                : - Nchannel = Nchannel_meg + Nchannel_ext + Nchannel_ref

 [note]
   See also
     vb_info_get_channel_info

 [history]
   2008-06-05 (Sako) initial version
   2009-07-07 (Sako) modified to get data from MEGinfo.ChannelInfo

 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 channel_info = vb_megfile_make_channel_info(megfile, ...
0002   meg_labels, ext_labels, ref_labels)
0003 % make ChannelInfo from channel label
0004 %
0005 % [usage]
0006 %   channel_info = vb_megfile_make_channel_info(megfile, ...
0007 %      meg_labels, ext_labels, ref_labels)
0008 %
0009 % [input]
0010 %      megfile : <required> <<file>> MEG-MAT file
0011 %   meg_labels : <optional> MEG channel label list       {Nchannel_meg x 1}
0012 %   ext_labels : <optional> EXTRA channel label list     {Nchannel_ext x 1}
0013 %   ref_labels : <optional> REFERENCE channel label list {Nchannel_ref x 1}
0014 %
0015 % [output]
0016 %   channel_info : <<struct>>
0017 %                :  .Active [Nchannel x 1]
0018 %                :  .Name   {Nchannel x 1}
0019 %                :  .Type   [Nchannel x 1]
0020 %                :  .ID     [Nchannel x 1]
0021 %                : - Nchannel = Nchannel_meg + Nchannel_ext + Nchannel_ref
0022 %
0023 % [note]
0024 %   See also
0025 %     vb_info_get_channel_info
0026 %
0027 % [history]
0028 %   2008-06-05 (Sako) initial version
0029 %   2009-07-07 (Sako) modified to get data from MEGinfo.ChannelInfo
0030 %
0031 % Copyright (C) 2011, ATR All Rights Reserved.
0032 % License : New BSD License(see VBMEG_LICENSE.txt)
0033 
0034 % --- CHECK ARGUMENTS --- %
0035 if ~exist('megfile', 'var'), megfile = ''; end
0036 if ~exist('meg_labels', 'var'), meg_labels = []; end
0037 if ~exist('ext_labels', 'var'), ext_labels = []; end
0038 if ~exist('ref_labels', 'var'), ref_labels = []; end
0039 [megfile, meg_labels, ext_labels, ref_labels] = ...
0040   inner_check_arguments(megfile, meg_labels, ext_labels, ref_labels);
0041 
0042 % --- MAIN PROCEDURE --------------------------------------------------------- %
0043 %
0044 channel_info.Active = [];
0045 channel_info.Name = [];
0046 channel_info.Type = [];
0047 channel_info.ID = [];
0048 
0049 meginfo = vb_megfile_load_meginfo(megfile);
0050 org_meg_ch_info = vb_info_get_channel_info(meginfo);
0051 if isempty(org_meg_ch_info)
0052   warning('(%s) cannot get channel information\n', mfilename);
0053   return;
0054 end
0055 
0056 org_ext_label = vb_meginfo_get_channel_label_extra(meginfo, false, true);
0057 
0058 if ~isempty(org_ext_label) && ~isempty(ext_labels)
0059   [tmp_ext_idx] = vb_util_get_index(org_ext_label, ext_labels);
0060 else
0061   tmp_ext_idx = [];
0062 end
0063 
0064 if ~isempty(org_ext_label) && ~isempty(ref_labels)
0065   [tmp_ref_idx] = vb_util_get_index(org_ext_label, ref_labels);
0066 else
0067   tmp_ref_idx = [];
0068 end
0069 
0070 
0071 if ~isempty(tmp_ext_idx) || ~isempty(tmp_ref_idx)
0072   if ~isfield(meginfo, 'ExtraChannelInfo') && isempty(meginfo.ExtraChannelInfo)
0073     warning('(%s)cannot get extra channel information\n', mfilename);
0074     return;
0075   else
0076     % --- correct extra channel information
0077     extra_info = meginfo.ExtraChannelInfo;
0078 
0079     % --- active of extra channel
0080     ext_active = extra_info.Channel_active(tmp_ext_idx);
0081     ref_active = extra_info.Channel_active(tmp_ref_idx);
0082 
0083     % --- type of extra channel
0084     ext_type = extra_info.Channel_type(tmp_ext_idx);
0085     ref_type = extra_info.Channel_type(tmp_ref_idx);
0086 
0087     % --- index of extra channel
0088     ext_idx = extra_info.Channel_id(tmp_ext_idx);
0089     ref_idx = extra_info.Channel_id(tmp_ref_idx);
0090   end
0091 else
0092   ext_active = [];
0093   ref_active = [];
0094   ext_type = [];
0095   ref_type = [];
0096   ext_idx = [];
0097   ref_idx = [];
0098 end
0099 
0100 % --- valid MEG channel index
0101 org_meg_label = vb_meginfo_get_channel_label_meg(meginfo, false);
0102 if ~isempty(org_meg_label) && ~isempty(meg_labels)
0103   [tmp_meg_idx] = vb_util_get_index(org_meg_label, meg_labels);
0104 else
0105   tmp_meg_idx = [];
0106 end
0107 
0108 % ----- Active
0109 org_meg_active = org_meg_ch_info.Active;
0110 meg_active = org_meg_active(tmp_meg_idx);
0111 channel_info.Active = [meg_active;ext_active;ref_active];
0112 
0113 % ----- Name
0114 org_meg_labels = org_meg_ch_info.Name;
0115 meg_labels = org_meg_labels(tmp_meg_idx);
0116 channel_info.Name = [meg_labels;ext_labels;ref_labels];
0117 
0118 % ----- Type
0119 org_meg_type = org_meg_ch_info.Type;
0120 meg_type = org_meg_type(tmp_meg_idx);
0121 channel_info.Type = [meg_type;ext_type;ref_type];
0122 
0123 % ----- ID
0124 org_meg_idx = org_meg_ch_info.ID;
0125 meg_idx = org_meg_idx(tmp_meg_idx);
0126 channel_info.ID = [meg_idx;ext_idx;ref_idx];
0127 
0128 return;
0129 %
0130 % --- END OF MAIN PROCEDURE -------------------------------------------------- %
0131 
0132 % --- INNER FUNCTIONS -------------------------------------------------------- %
0133 %
0134 % --- inner_check_arguments()
0135 %
0136 function [megfile, meg_labels, ext_labels, ref_labels] = ...
0137   inner_check_arguments(megfile, meg_labels, ext_labels, ref_labels)
0138 func_ = mfilename;
0139 if isempty(megfile)
0140   error('(%s)megfile is a required parameter', func_);
0141 end
0142 
0143 if exist(megfile, 'file') ~= 2
0144   error('(%s)cannot find megfile : %s', func_, megfile);
0145 end
0146 return;
0147 %
0148 % --- end of inner_check_arguments()
0149 %
0150 % --- END OF INNER FUNCTIONS ------------------------------------------------- %
0151 
0152 %--- END OF FILE ---%

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