Home > vbmeg > functions > device > active_check > vb_fileinfo_active_field_convert_to.m

vb_fileinfo_active_field_convert_to

PURPOSE ^

convert fileinfo active part format from new to old or old to new.

SYNOPSIS ^

function fileinfo = vb_fileinfo_active_field_convert_to(format, fileinfo, data_file)

DESCRIPTION ^

 convert fileinfo active part format from new to old or old to new.
 * Think not to use this function as possible, please use new fields.
    fileinfo.ActiveChannel
    fileinfo.ActiveTrial.

 [Usage]
    fileinfo = vb_fileinfo_active_field_convert_to(format, fileinfo, data_file);

 [Input]
    format     : converted format. [string]
                 = 'new' : old format to new format.
                 = 'old' : new format to old format.
    fileinfo   : fileinfo struct.
    data_file  : fileinfo file.

 [Output]
      fileinfo : converted fileinfo.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function fileinfo = vb_fileinfo_active_field_convert_to(format, fileinfo, data_file)
0002 % convert fileinfo active part format from new to old or old to new.
0003 % * Think not to use this function as possible, please use new fields.
0004 %    fileinfo.ActiveChannel
0005 %    fileinfo.ActiveTrial.
0006 %
0007 % [Usage]
0008 %    fileinfo = vb_fileinfo_active_field_convert_to(format, fileinfo, data_file);
0009 %
0010 % [Input]
0011 %    format     : converted format. [string]
0012 %                 = 'new' : old format to new format.
0013 %                 = 'old' : new format to old format.
0014 %    fileinfo   : fileinfo struct.
0015 %    data_file  : fileinfo file.
0016 %
0017 % [Output]
0018 %      fileinfo : converted fileinfo.
0019 %
0020 
0021 %
0022 % --- Previous check
0023 %
0024 if ~exist('format', 'var')
0025     error('format is required parameter.');
0026 end
0027 if ~exist('fileinfo', 'var')
0028     error('fileinfo is required parameter.');
0029 end
0030 if ~exist('data_file', 'var')
0031     error('fileinfo is required parameter.');
0032 end
0033 if exist(data_file, 'file') ~= 2
0034     error('Specified data_file not found.');
0035 end
0036 
0037 %
0038 % --- Main procedure
0039 %
0040 if isfield(fileinfo, 'channel_id')
0041     current_format = 'old';
0042 elseif isfield(fileinfo, 'ActiveChannel')
0043     current_format = 'new';
0044 end
0045 
0046 % No need to convert
0047 if strcmp(current_format, format), return; end
0048 
0049 % convert
0050 ch_info = vb_load_channel_info(data_file);
0051 
0052 switch(format)
0053     case 'old'
0054         % new to old
0055         fileinfo.channel_id = ch_info.ID(fileinfo.ActiveChannel ~= 0);
0056         fileinfo.act_trial  = find(fileinfo.ActiveTrial ~= 0);
0057 
0058         % remove new field
0059         fileinfo = rmfield(fileinfo, 'ActiveChannel');
0060         fileinfo = rmfield(fileinfo, 'ActiveTrial');
0061 
0062     case 'new'
0063         % old to new
0064         ix = vb_util_get_index(ch_info.ID, fileinfo.channel_id);
0065         fileinfo.ActiveChannel = zeros(length(fileinfo.Nchannel), 1);
0066         fileinfo.ActiveChannel(ix) = 1;
0067         fileinfo.ActiveTrial = zeros(length(fileinfo.Ntotal), 1);
0068         fileinfo.ActiveTrial(fileinfo.act_trial) = 1;
0069         % remove new field
0070         fileinfo = rmfield(fileinfo, 'channel_id');
0071         fileinfo = rmfield(fileinfo, 'act_trial');
0072 
0073     otherwise
0074         error('Invalid format was specified.');
0075 end
0076

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