0001 function [trial, id_list] = vb_info_get_trial_data(info, trial_id, field_name)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
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
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
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
0067 trial = vb_util_arrange_list(trial, 0);
0068 id_list = vb_util_arrange_list(id_list, 0);
0069 return;
0070 end
0071
0072
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
0101 trial = vb_util_arrange_list(trial, 0);
0102 id_list = vb_util_arrange_list(id_list, 0);
0103 return;
0104
0105
0106
0107
0108
0109
0110
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
0128 end
0129
0130 if isempty(field_name)
0131
0132 end
0133 return;
0134
0135
0136
0137
0138
0139