Commit e2f4e849 authored by Brad Kennedy's avatar Brad Kennedy
Browse files

Updated values2flags to be more readable

parent ae1f146b
function [critrow,critcol,rowind,colind]=values2flags(EEG,inmeasure,flagdir,flagzcrit,critdir,critmethod,critvalue,chan_win_sd,varargin)
g=struct(varargin{:});
try g.trim; catch, g.trim=0; end;
%try g.fisherz; catch, g.fisherz='off'; end;
try g.plot_figs; catch, g.plot_figs='off';end;
% values2flags() - description of the function. If less than
%
%
% Usage:
% >> [critrow, critcol, rowind, colind] = values2flags(~, ...
% inmeasure, flagdir, flagzcrit, critdir, critmethod, critvalue, ...
% chan_win_sd,varargin)
%
% Inputs:
% ~ - unused
% inmeasure -
% flagdir -
% flagzcrit -
% critdir -
% critmethod -
% critvalue -
% chan_win_sd -
%
% Variable args:
% 'plot_figs': 'on' - specifies to plot 'trim' : use trimmed mean
% 'trim': true - specifies to use trimmed mean
% Outputs:
% OUTEEG - output dataset
%
% See also:
% SAMPLE, EEGLAB
% TODO(brad) we need argument comments
% Copyright (C) 2017 Brock University Cognitive and Affective Neuroscience Lab
%
% Code written by Allan Campopiano, Andrew Lofts, James Desjardins,
% Brad Kennedy
%
% This program is free software; you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation; either version 2 of the License, or
% (at your option) any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program (LICENSE.txt file in the root directory); if not,
% write to the Free Software Foundation, Inc., 59 Temple Place,
% Suite 330, Boston, MA 02111-1307 USA
function [critrow, critcol, rowind, colind] = values2flags(~, ...
inmeasure, flagdir, flagzcrit, critdir, critmethod, critvalue, ...
chan_win_sd, varargin)
g = struct(varargin{:});
if ~isfield(g, 'trim'), g.trim = 0; end;
if ~isfield(g, 'plot_figs'), g.plot_figs = false; end;
g.plot_figs = strcmp(g.plot_figs, 'on');
critrow=[];
critcol=[];
rowind=[];
colind=[];
if strcmp(g.plot_figs,'on')
if g.plot_figs
figure;
subplot(3,3,[2,3,5,6]);surf(double(inmeasure),'LineStyle','none');
axis('tight');
......@@ -25,83 +77,64 @@ if strcmp(g.plot_figs,'on')
axis('tight');
end
s_thresh=[];
if ~isempty(chan_win_sd);
m_chan_win_sd=mean(chan_win_sd,2);
s_chan_win_sd=std(chan_win_sd,[],2);
s_thresh=m_chan_win_sd-s_chan_win_sd*1;
s_thresh=m_chan_win_sd-s_chan_win_sd;
if strcmp(g.plot_figs,'on')
figure;plot(s_thresh);
figure; plot(s_thresh);
figure;
subplot(3,3,[2,3,5,6]);surf(double(chan_win_sd),'LineStyle','none');
subplot(3,3,[2,3,5,6]);
surf(double(chan_win_sd),'LineStyle','none');
axis('tight');
view(0,90);
subplot(3,3,[1,4]);plot(squeeze(mean(chan_win_sd,2)));
subplot(3,3,[1,4]); plot(squeeze(mean(chan_win_sd,2)));
axis('tight');
view(270,90)
subplot(3,3,[8,9]);plot(squeeze(mean(chan_win_sd,1)));
subplot(3,3,[8,9]); plot(squeeze(mean(chan_win_sd,1)));
axis('tight');
end
else
s_thresh=[];
end
%if strcmp(g.fisherz,'on');
% for i=1:size(inmeasure,1);
% inmeasure(i,:)=.5.*log((1+inmeasure(i,:))./(1-inmeasure(i,:)));
% end
%end
if flagdir==1||flagdir==3;
if flagdir==1 || flagdir==3
critrow=zeros(size(inmeasure));
mrrow = zeros(size(inmeasure,2));
srrow = zeros(size(inmeasure,2));
colind=1:size(inmeasure,2);
nCol=length(colind);
if strcmp(g.plot_figs,'on')
if g.plot_figs
hrowc = waitbar(0,['Testing column 0 of ', num2str(nCol), '...']);
end
for coli=colind;
if strcmp(g.plot_figs,'on')
if g.plot_figs
waitbar(coli/nCol,hrowc, ...
['Testing column ', num2str(coli), ' of ', num2str(nCol), '...']);
end
if g.trim==0;
if g.trim == 0;
mrrow(coli)=mean(inmeasure(:,coli),1);
srrow(coli)=std(inmeasure(:,coli),[],1);
else
mrrow(coli)=ve_trimmean(inmeasure(:,coli),g.trim);
srrow(coli)=ve_trimstd(inmeasure(:,coli),g.trim);
end
for rowi=1:size(inmeasure,1);
if strcmp(critdir,'pos');
if inmeasure(rowi,coli)>mrrow(coli)+srrow(coli)*flagzcrit;
if ~isempty(s_thresh);
if chan_win_sd(rowi,coli)>s_thresh(rowi);
critrow(rowi,coli)=1;
end
else
critrow(rowi,coli)=1;
end
end
do_crit = inmeasure(rowi,coli)>mrrow(coli)+srrow(coli)*flagzcrit;
else
if inmeasure(rowi,coli)<mrrow(coli)-srrow(coli)*flagzcrit;
if ~isempty(s_thresh);
if chan_win_sd(rowi,coli)>s_thresh(rowi);
critrow(rowi,coli)=1;
end
else
critrow(rowi,coli)=1;
end
end
do_crit = inmeasure(rowi,coli)<mrrow(coli)-srrow(coli)*flagzcrit;
end
critrow(rowi,coli) = ...
do_crit && ((~isempty(s_thresh) && ...
chan_win_sd(rowi,coli)>s_thresh(rowi)) || ...
isempty(s_thresh));
end
end
if strcmp(g.plot_figs,'on')
if g.plot_figs
close(hrowc);
end
......@@ -119,10 +152,8 @@ if flagdir==1||flagdir==3;
rowind=find(rowcritrow>rowthresh);
colcritrow=squeeze(mean(critrow,1));
mrcritrow=mean(colcritrow);
srcritrow=std(colcritrow);
if strcmp(g.plot_figs,'on')
if g.plot_figs
figure;
subplot(3,3,[2,3,5,6]);surf(critrow,'LineStyle','none');
axis('tight');
......@@ -133,25 +164,26 @@ if flagdir==1||flagdir==3;
axis('tight');
view(270,90)
subplot(3,3,[8,9]);plot(colcritrow);
subplot(3,3,[8,9]); plot(colcritrow);
axis('tight');
end
end
if flagdir==2||flagdir==3;
if flagdir == 2 || flagdir == 3;
critcol=zeros(size(inmeasure));
colind=1:size(inmeasure,2);
rowind=1:size(inmeasure,1);
nRow=length(rowind);
if strcmp(g.plot_figs,'on')
if g.plot_figs
hcolc = waitbar(0,['Testing row 0 of ', nRow, '...']);
end
mrcol = zeros(size(inmeasure,1));
srcol = zeros(size(inmeasure,1));
for rowi=rowind;
if strcmp(g.plot_figs,'on')
if g.plot_figs
waitbar(0,hcolc, ...
['Testing row ', num2str(rowi), ' of ', num2str(nRow), '...']);
end
......@@ -159,37 +191,22 @@ if flagdir==2||flagdir==3;
srcol(rowi)=std(inmeasure(rowi,:),[],2);
for coli=1:size(inmeasure,2);
if strcmp(critdir,'pos');
if inmeasure(rowi,coli)>mrcol(rowi)+srcol(rowi)*flagzcrit;
if ~isempty(s_thresh);
if chan_win_sd(rowi,coli)>s_thresh(rowi);
critcol(rowi,coli)=1;
end
else
critcol(rowi,coli)=1;
end
end
do_crit = inmeasure(rowi,coli)>mrcol(rowi)+srcol(rowi)*flagzcrit;
else
if inmeasure(rowi,coli)<mrcol(rowi)-srcol(rowi)*flagzcrit;
if ~isempty(s_thresh);
if chan_win_sd(rowi,coli)>s_thresh(rowi);
critcol(rowi,coli)=1;
end
else
critcol(rowi,coli)=1;
end
end
do_crit = inmeasure(rowi,coli)<mrcol(rowi)-srcol(rowi)*flagzcrit;
end
critcol(rowi,coli) = ...
do_crit && ((~isempty(s_thresh) && ...
chan_win_sd(rowi,coli)>s_thresh(rowi)) || ...
isempty(s_thresh));
end
end
if strcmp(g.plot_figs,'on')
if g.plot_figs
close(hcolc);
end
rowcritcol=squeeze(mean(critcol,2));
mrcritcol=mean(rowcritcol);
srcritcol=std(rowcritcol);
colcritcol=squeeze(mean(critcol,1));
mccritcol=mean(colcritcol);
sccritcol=std(colcritcol);
......@@ -203,7 +220,7 @@ if flagdir==2||flagdir==3;
colind=find(colcritcol>colthresh);
if strcmp(g.plot_figs,'on')
if g.plot_figs
figure;
subplot(3,3,[2,3,5,6]);surf(critcol,'LineStyle','none');
axis('tight');
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment