0001 function [fileinfo,flg,data] = ...
0002 vb_job_bad_trial_stat(datafile,job_mode,actfile,stat_file, ...
0003 thred_val_lst,prob_val_lst,plist,thred_ch,std_mode)
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042 if ~exist('std_mode','var') , std_mode = 1; end;
0043
0044 if ~isempty(datafile) && ~iscell(datafile),
0045 tmp = datafile;
0046 datafile = {tmp};
0047 end;
0048
0049 if exist('stat_file','var') && exist([stat_file '.info.mat'],'file')
0050
0051 load([stat_file '.info.mat'])
0052 else
0053
0054
0055 fileinfo = vb_get_multi_fileinfo(datafile);
0056 end
0057
0058
0059
0060
0061
0062
0063 if isfield(fileinfo,'ymax1')
0064 ymax1 = fileinfo.ymax1;
0065 ymax2 = fileinfo.ymax2;
0066 ystd1 = fileinfo.ystd1;
0067 ystd2 = fileinfo.ystd2;
0068 if ~isempty(datafile)
0069 fileinfo = vb_get_multi_fileinfo(datafile);
0070 end
0071 else
0072 ymax1 = [];
0073 ymax2 = [];
0074 ystd1 = [];
0075 ystd2 = [];
0076 fprintf('Load data ')
0077 for n=1:length(datafile)
0078
0079 fprintf('-')
0080 temp = vb_load_meg_data(datafile{n});
0081 [max1,max2,std1,std2] = vb_channel_statics(temp);
0082 ymax1 = [ymax1 , max1];
0083 ymax2 = [ymax2 , max2];
0084 ystd1 = [ystd1 , std1];
0085 ystd2 = [ystd2 , std2];
0086 end
0087 fprintf('\n')
0088 end
0089
0090
0091 if std_mode == 0
0092 ystd1 = mean(ystd1,2);
0093 ystd2 = mean(ystd2,2);
0094 end
0095
0096 ratio1 = ymax1;
0097 ratio2 = ymax2;
0098
0099 ix1 = find(ystd1 > 0);
0100 ix2 = find(ystd2 > 0);
0101
0102 if size(ystd1,2) == 1
0103 ratio1(ix1,:) = vb_repmultiply(ymax1(ix1,:), 1./ystd1(ix1));
0104 ratio2(ix2,:) = vb_repmultiply(ymax2(ix2,:), 1./ystd2(ix2));
0105 else
0106 ratio1(ix1) = ymax1(ix1)./ystd1(ix1);
0107 ratio2(ix2) = ymax2(ix2)./ystd2(ix2);
0108 end
0109
0110
0111
0112
0113
0114
0115
0116
0117
0118
0119
0120 flg = [];
0121 data = [];
0122
0123 [Nch,Ntry] = size(ratio1);
0124 thred_num = Nch * thred_ch;
0125
0126 if ~exist('thred_val_lst','var')||isempty(thred_val_lst)
0127 thred_val_lst1 = [8:11];
0128 thred_val_lst2 = [7:10];
0129 else
0130 thred_val_lst1 = thred_val_lst(1,:);
0131 thred_val_lst2 = thred_val_lst(2,:);
0132 end
0133 if ~exist('prob_val_lst','var')||isempty(prob_val_lst)
0134 prob_val_lst = [0.02:0.01:0.05];
0135 end
0136 if ~exist('plist','var')||isempty(plist)
0137 plist = [0.05 0.01 0.001];
0138 end
0139
0140 switch job_mode
0141 case 0
0142
0143 subplot 121
0144 [ylist1,h1,y1] = vb_plot_stat_hist(ratio1 ,plist);
0145 hold on
0146 title('Max/std of amplitude')
0147 subplot 122
0148 [ylist2,h2,y2] = vb_plot_stat_hist(ratio2 ,plist);
0149 hold on
0150 title('Max/std of derivative')
0151
0152
0153 flg = [ylist1; ylist2];
0154 data = [h1(:), y1(:), h2(:), y2(:)];
0155
0156 case 1
0157
0158 subplot 121
0159 [ylist1,h1,y1] = vb_plot_stat_hist(ratio1 ,plist);
0160 hold on
0161 title('Max/std of amplitude')
0162 subplot 122
0163 [ylist2,h2,y2] = vb_plot_stat_hist(ratio2 ,plist);
0164 hold on
0165 title('Max/std of derivative')
0166
0167
0168 flg = [ylist1; ylist2];
0169 data = [h1(:), y1(:), h2(:), y2(:)];
0170
0171
0172 vb_plot_max_ratio_image(ratio1,thred_val_lst1)
0173 vb_plot_max_ratio_image(ratio2,thred_val_lst2)
0174 vb_plot_channel_trial(ratio1,ratio2, ...
0175 thred_val_lst1,thred_val_lst2,prob_val_lst,thred_num)
0176 end
0177
0178 ch_act = 1:Nch;
0179 try_act = 1:Ntry;
0180 try_err = [];
0181
0182
0183 fileinfo.ymax1 = ymax1;
0184 fileinfo.ymax2 = ymax2;
0185 fileinfo.ystd1 = ystd1;
0186 fileinfo.ystd2 = ystd2;
0187
0188 fileinfo.channel_id = ch_act;
0189 fileinfo.act_trial = try_act;
0190 fileinfo.err_trial = try_err;
0191
0192 if ~exist('actfile','var')||isempty(actfile), return;end
0193
0194
0195 fprintf('Save trial statistics info to: %s\n',[actfile '.info.mat'])
0196
0197 vb_fsave([actfile '.info.mat'],'fileinfo');