Home > vbmeg > functions > device > vb_info_get_trial_data.m

vb_info_get_trial_data

PURPOSE ^

return trial data that you want from info.Trial struct

SYNOPSIS ^

function [trial, id_list] = vb_info_get_trial_data(info, trial_id, field_name)

DESCRIPTION ^

 return trial data that you want from info.Trial struct
 [usage]
   [trial, id_list] = vb_info_get_trial_data(info, trial_id, field_name)
 [input]
         info : <required> <<struct>> MEGinfo or EEGinfo
              :  which must have Trial field
     trial_id : <optional> [Ntrial_req x 1]
              :  if this is empty, return all trial data
   field_name : <optional> <<string>> you can get only a field data you want
 [output]
     trial : required data [Ntrial_req x 1]
   id_list : trial ID list of returned data
 [note]
   MEGinfo.Trial [Ntrial x 1 struct]
     .number [x1] trial number when this data was imported
     .sample [Nsample x 1] list of sample numbers
     .Active [x1] <<boolean>>
 [history]
   2009-07-13 (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 [trial, id_list] = vb_info_get_trial_data(info, trial_id, field_name)
0002 % return trial data that you want from info.Trial struct
0003 % [usage]
0004 %   [trial, id_list] = vb_info_get_trial_data(info, trial_id, field_name)
0005 % [input]
0006 %         info : <required> <<struct>> MEGinfo or EEGinfo
0007 %              :  which must have Trial field
0008 %     trial_id : <optional> [Ntrial_req x 1]
0009 %              :  if this is empty, return all trial data
0010 %   field_name : <optional> <<string>> you can get only a field data you want
0011 % [output]
0012 %     trial : required data [Ntrial_req x 1]
0013 %   id_list : trial ID list of returned data
0014 % [note]
0015 %   MEGinfo.Trial [Ntrial x 1 struct]
0016 %     .number [x1] trial number when this data was imported
0017 %     .sample [Nsample x 1] list of sample numbers
0018 %     .Active [x1] <<boolean>>
0019 % [history]
0020 %   2009-07-13 (Sako) initial version
0021 %
0022 % Copyright (C) 2011, ATR All Rights Reserved.
0023 % License : New BSD License(see VBMEG_LICENSE.txt)
0024 
0025 % --- CHECK ARGUMENTS --- %
0026 if ~exist('info', 'var'), info = []; end
0027 if ~exist('trial_id', 'var'), trial_id = []; end
0028 if ~exist('field_name', 'var'), field_name = ''; end
0029 [info, trial_id, field_name] = ...
0030   inner_check_arguments(info, trial_id, field_name);
0031 
0032 % --- MAIN PROCEDURE --------------------------------------------------------- %
0033 %
0034 if isempty(info)
0035   trial = [];
0036   id_list = [];
0037   return;
0038 end
0039 
0040 n_trial = length(info.Trial);
0041 
0042 if isempty(trial_id)
0043   % --- data of all the channels
0044   id_list = zeros(n_trial,1);
0045   for i_tr = 1:n_trial
0046     id_list(i_tr) = info.Trial(i_tr).number;
0047   end
0048 
0049   if isempty(field_name)
0050     trial = info.Trial;
0051   elseif strcmp(field_name, 'number') || strcmp(field_name, 'Active')
0052     exec_str = sprintf('trial = [info.Trial.%s];', field_name);
0053     eval(exec_str);
0054 
0055   elseif strcmp(field_name, 'sample')
0056     for i_tr = 1:n_trial
0057       trial(i_tr,:) = info.Trial(i_tr).sample;
0058     end
0059 
0060   else
0061     warning('(%s) unknown field of Trial : %s - return all\n', ...
0062       mfilename, field_name);
0063     trial = info.Trial;
0064   end
0065 
0066   % --- arrange to [N x 1]
0067   trial = vb_util_arrange_list(trial, 0);
0068   id_list = vb_util_arrange_list(id_list, 0);
0069   return;
0070 end
0071 
0072 % --- the case that trial id is specified
0073 n_trial_req = length(trial_id);
0074 
0075 n_return = 0;
0076 
0077 for i_req = 1:n_trial_req
0078   
0079   cur_id = trial_id(i_req);
0080   
0081   for i_trial = 1:n_trial
0082     
0083     cur_trial = info.Trial(i_trial);
0084 
0085     if cur_id == cur_trial.number
0086       n_return = n_return + 1;
0087       id_list(n_return) = cur_id;
0088 
0089       if isempty(field_name)
0090         trial(n_return) = cur_trial;
0091       else
0092         exec_str = sprintf('trial(%d) = cur_trial.%s', n_return, field_name);
0093         eval(exec_str);
0094       end
0095       break;
0096     end
0097   end
0098 end
0099 
0100 % --- arrange to [N x 1]
0101 trial = vb_util_arrange_list(trial, 0);
0102 id_list = vb_util_arrange_list(id_list, 0);
0103 return;
0104 %
0105 % --- END OF MAIN PROCEDURE -------------------------------------------------- %
0106 
0107 
0108 % --- INNER FUNCTIONS -------------------------------------------------------- %
0109 %
0110 % --- inner_check_arguments()
0111 %
0112 function [info, trial_id, field_name] = ...
0113   inner_check_arguments(info, trial_id, field_name)
0114 func_ = mfilename;
0115 
0116 if isempty(info)
0117   error('(%s) info is a required parameter', func_);
0118 end
0119 
0120 if ~isfield(info, 'Trial')
0121   info = [];
0122   warning('(%s) This info does not have ''Trial'' field\n', func_);
0123   return;
0124 end
0125 
0126 if isempty(trial_id)
0127   % require no action
0128 end
0129 
0130 if isempty(field_name)
0131   % require no action
0132 end
0133 return;
0134 %
0135 % --- end of inner_check_arguments()
0136 %
0137 % --- END OF INNER FUNCTIONS ------------------------------------------------- %
0138 
0139 %%% END OF FILE %%%

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