0001 function ch_bad = vb_plot_bad_channels2(data,ix_ch,flg, varargin)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 PARM = finputcheck(varargin, ...
0014 {
0015 'BACKCOLOR' 'real' [] [0 0 0]; ...
0016 'CUIBUTTONCOLOR' 'real' [] [.8 .8 .8]; ...
0017 'FIGSIZE' 'real' [] get(0,'monitorpositions')*0.95;...
0018 'TSTEP' 'integer' [] 5;...
0019 'label' 'integer' [] [1:size(data,3)];...
0020 'ylimits' 'real' [] []});
0021 if ischar(PARM)
0022 error(PARM);
0023 end
0024
0025 BACKCOLOR = PARM.BACKCOLOR;
0026 GUIBUTTONCOLOR = PARM.CUIBUTTONCOLOR;
0027 FIGSIZE = PARM.FIGSIZE;
0028 TSTEP = PARM.TSTEP;
0029 label = PARM.label;
0030 ylimits = PARM.ylimits;
0031 if isempty(ylimits), ylimits = [-max(abs(data(:))) max(abs(data(:)))]; end
0032
0033
0034
0035
0036 flgsum=sum(flg(ix_ch,:),2);
0037 [flgsumsort,jx_ch_sort]=sort(flgsum(:),1,'descend');
0038 ix_ch_sort = ix_ch(jx_ch_sort);
0039
0040 y = data(ix_ch_sort,:,:);
0041 nch = length(ix_ch);
0042 pannel_rej = [];
0043
0044
0045
0046
0047 column =ceil(sqrt( nch ))+1;
0048 rows = ceil(nch/column);
0049
0050 hfig = figure('name', [ 'Channel Rejection'], 'tag', 'main', ...
0051 'numbertitle', 'off', 'color', BACKCOLOR, 'windowstyle', 'modal', 'position', FIGSIZE);
0052 set(hfig,'MenuBar', 'none');
0053 incx = 120;
0054 incy = 110;
0055 sizewx = 100/column;
0056 if rows > 2
0057 sizewy = 90/rows;
0058 else
0059 sizewy = 80/rows;
0060 end;
0061 pos = get(gca,'position');
0062 q = [pos(1) pos(2) 0 0];
0063 s = [pos(3) pos(4) pos(3) pos(4)]./100;
0064 axis off;
0065
0066
0067
0068 count = 1;
0069 for ch = 1 : nch
0070
0071 X = mod(count-1, column)/column * incx-10;
0072 Y = (rows-floor((count-1)/column))/rows * incy - sizewy*1.3;
0073
0074 if ~strcmp(get(gcf, 'tag'), 'main');
0075 disp('Aborting plot');
0076 return;
0077 end;
0078
0079
0080
0081 haxes(ch) = axes('Units','Normalized', 'Position',[X Y sizewx sizewy].*s+q);
0082 plot([1:TSTEP:size(y,2)],squeeze(y(ch,1:TSTEP:end,:)))
0083 set_axis
0084 axis([-inf inf ylimits]);
0085 axis on
0086
0087
0088
0089
0090 set(haxes(ch),'buttondownfcn', @rej_callback_axisbuttondwn,...
0091 'color', get(hfig,'color'),'xcolor','w','ycolor','w');
0092
0093
0094
0095
0096
0097 hc = get(haxes(ch),'children');
0098 for cc = 1 : length(hc), set(hc(cc),'Hittest', 'off'); end
0099
0100
0101
0102
0103
0104 hcheck(ch) = uicontrol(hfig, 'Style', 'checkbox', 'Units','Normalized', 'Position',...
0105 [X Y+sizewy sizewx sizewy*0.25].*s+q, 'value', 1, 'String', ['Ch' num2str(label(ix_ch_sort(ch)))], 'callback', @rej_callback_checkbox);
0106
0107 drawnow;
0108 count = count +1;
0109 end;
0110
0111
0112
0113 hcancel = uicontrol(hfig, 'Style', 'pushbutton', 'string', 'Cancel', 'Units','Normalized', 'backgroundcolor', GUIBUTTONCOLOR, ...
0114 'Position',[50 -10 15 sizewy*0.25].*s+q, 'callback', 'close(gcf); fprintf(''Operation cancelled\n'')' );
0115
0116 hok = uicontrol(hfig, 'Style', 'pushbutton', 'string', 'OK', 'Units','Normalized', 'backgroundcolor', GUIBUTTONCOLOR, ...
0117 'Position',[90 -10 15 sizewy*0.25].*s+q, 'callback', @rej_callback_mainokbutton);
0118
0119 hall = uicontrol(hfig, 'Style', 'pushbutton', 'string', 'ALL OFF', 'Units','Normalized', 'backgroundcolor', GUIBUTTONCOLOR, ...
0120 'Position',[70 -10 15 sizewy*0.25].*s+q, 'callback', @rej_callback_allbutton);
0121
0122 fprintf('press any keys \n');
0123 pause
0124
0125 ch_bad = ix_ch_sort(pannel_rej);
0126
0127
0128
0129
0130
0131
0132 function rej_callback_checkbox(hObject,eventdata)
0133
0134 end
0135
0136 function rej_callback_allbutton(hObject,eventdata)
0137 for ii = 1 : length(hcheck)
0138 set(hcheck(ii),'value',0);
0139 end
0140 end
0141
0142 function rej_callback_mainokbutton(hObject,eventdata)
0143
0144 pannel_rej = [];
0145 for ii = 1 : length(hcheck)
0146 val = get(hcheck(ii),'value');
0147 if val == 1
0148 pannel_rej = [pannel_rej ii];
0149 end
0150 end
0151 close(hfig);
0152 figures = findobj('Tag', 'vb_plot_bad_channels2_detail');
0153 for k=1:length(figures)
0154 h_detail = figures(k);
0155 if ishandle(h_detail) ~= -1
0156 close(h_detail);
0157 end
0158 end
0159 end
0160
0161
0162 function rej_callback_axisbuttondwn(hObject,eventdata)
0163
0164 hcurraxes = hObject;
0165 pannel_ind = find(haxes == hcurraxes);
0166 ytmp = squeeze(y(pannel_ind,:,:));
0167
0168 h = figure;
0169 set(h, 'Tag', 'vb_plot_bad_channels2_detail');
0170 plot(ytmp(:));
0171 title(['Ch= ' num2str(label(ix_ch_sort(pannel_ind)))])
0172 xlabel('time points')
0173 ylabel('amplitude')
0174 end
0175
0176
0177 end