From 3067c78f545ceb70daf045fe1c6ce1d63b333784 Mon Sep 17 00:00:00 2001 From: mattansb <35330040+mattansb@users.noreply.github.com> Date: Sun, 23 Sep 2018 13:27:59 +0300 Subject: [PATCH] new tbt_plot --- tbt/tbt_plot.m | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 tbt/tbt_plot.m diff --git a/tbt/tbt_plot.m b/tbt/tbt_plot.m new file mode 100644 index 0000000..3741dd2 --- /dev/null +++ b/tbt/tbt_plot.m @@ -0,0 +1,61 @@ +function plot_bads = tbt_plot(EEG,bads,bTrial_ind,bChan_ind) + +plot_bads = 1; + +%% Plot Matrix at a glance + +% Prep for plotting +forplot_bads = double(~bads); +forplot_bads(:,bTrial_ind) = EEG.trials + 1; +for tr = 1:EEG.trials + forplot_bads(bads(:,tr),tr) = tr; +end +forplot_bads(bChan_ind,:) = EEG.trials + 1; + +% Plot +figure; imagesc(forplot_bads); +colormap([1 1 1; rand([EEG.trials 3]); [1 .25 .25]]) +title('Bad channels by trial') +xlabel('Trial'); ylabel('Channel'); +yticks(1:EEG.nbchan); yticklabels({EEG.chanlocs.labels}); +annotation('textbox', [0.1, 0.07, 0, 0],... + 'String', 'Each trial is marked by a color. Red lines indicate a channel or trial that will be completelty removed. ',... + 'FitBoxToText', 'on', 'LineStyle', 'none'); + +%% Plot EEG + +% Prep for plotting +mark = ones([0,5] + size(bads')); +mark(:,6:end) = double(bads'); +mark(:,1) = 1:EEG.pnts:EEG.pnts*EEG.trials; % start sample +mark(:,2) = mark(:,1)+EEG.pnts; % end sample +mark(bTrial_ind,3) = 1; % R for bad trials +mark(bTrial_ind,4) = 0.9; % G for bad trials +mark(bTrial_ind,5) = 0.7; % B for bad trials + +% Plot +eegplot(EEG.data(:,:,:), 'winrej',mark, 'events', EEG.event ,... + 'srate', EEG.srate, 'limits', [EEG.xmin EEG.xmax]*1000); + +%% Wait for respons +uiwait(gcf); +dlgmsstxt = sprintf(... + ['%d trial and %d channels will be completely removed. Additionally:\n'... + '%d channel(s) are bad on at least 1 trial.\n'... + '%d trial(s) contain at least 1 bad channel\n'... + '\n',... + 'Proceed?'],... + sum(bTrial_ind),... + sum(bChan_ind),... + sum(any(bads(~bChan_ind,~bTrial_ind),2)),... + sum(any(bads(~bChan_ind,~bTrial_ind),1))); + +choice = questdlg(... + dlgmsstxt, ... + 'Confirm', ... + 'Yes','No (do nothing)','Yes'); +switch choice + case 'Yes' + plot_bads = 0; +end +end \ No newline at end of file