values2flags.m 6.2 KB
Newer Older
Allan Campopiano's avatar
Allan Campopiano committed
1
2
function [critrow,critcol,rowind,colind]=values2flags(EEG,inmeasure,flagdir,flagzcrit,critdir,critmethod,critvalue,chan_win_sd,varargin)

3
4
disp('WARNING: This function is DEPRECATED and not supported anymore. Use marks_array2flags.m instead.');

Allan Campopiano's avatar
Allan Campopiano committed
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
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;

critrow=[];
critcol=[];
rowind=[];
colind=[];

if strcmp(g.plot_figs,'on')
    figure;
    subplot(3,3,[2,3,5,6]);surf(double(inmeasure),'LineStyle','none');
    axis('tight');
    view(0,90);
    
    subplot(3,3,[1,4]);plot(squeeze(mean(inmeasure,2)));
    axis('tight');
    view(270,90)
    
    subplot(3,3,[8,9]);plot(squeeze(mean(inmeasure,1)));
    axis('tight');
end

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;
    
    if strcmp(g.plot_figs,'on')
        figure;plot(s_thresh);
        figure;
        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)));
        axis('tight');
        view(270,90)
        
        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;
    
    critrow=zeros(size(inmeasure));
    colind=1:size(inmeasure,2);
    nCol=length(colind);
    if strcmp(g.plot_figs,'on')
        hrowc = waitbar(0,['Testing column 0 of ', num2str(nCol), '...']);
    end
    for coli=colind;
        if strcmp(g.plot_figs,'on')
            waitbar(coli/nCol,hrowc, ...
                ['Testing column ', num2str(coli), ' of ', num2str(nCol), '...']);
        end
        if g.trim==0;
            mrrow(coli)=mean(inmeasure(:,coli),1);
            srrow(coli)=std(inmeasure(:,coli),[],1);
        else
76

77
78
            mrrow(coli)=ve_trimmean(inmeasure(:,coli),g.trim);
            srrow(coli)=ve_trimstd(inmeasure(:,coli),g.trim);
79

Allan Campopiano's avatar
Allan Campopiano committed
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
        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
            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
            end
        end
    end
    
    if strcmp(g.plot_figs,'on')
        close(hrowc);
    end
    
    rowcritrow=squeeze(mean(critrow,2));
    mccritrow=mean(rowcritrow);
    sccritrow=std(rowcritrow);

    switch (critmethod);
        case 'fixed';
            rowthresh=critvalue;
        case 'distrib'
            rowthresh=mccritrow+sccritrow*critvalue;
    end
    
    rowind=find(rowcritrow>rowthresh);
    
    colcritrow=squeeze(mean(critrow,1));
    mrcritrow=mean(colcritrow);
    srcritrow=std(colcritrow);
    
    if strcmp(g.plot_figs,'on')
        figure;
        subplot(3,3,[2,3,5,6]);surf(critrow,'LineStyle','none');
        axis('tight');
        view(0,90);
        
        subplot(3,3,[1,4]);plot(rowcritrow);
        hold on;plot(ones(size(rowcritrow))*rowthresh,'r');
        axis('tight');
        view(270,90)
        
        subplot(3,3,[8,9]);plot(colcritrow);
        axis('tight');
    end
end


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')
        hcolc = waitbar(0,['Testing row 0 of ', nRow, '...']);
    end
    
    for rowi=rowind;
        if strcmp(g.plot_figs,'on')
            waitbar(0,hcolc, ...
                ['Testing row ', num2str(rowi), ' of ', num2str(nRow), '...']);
        end
        mrcol(rowi)=mean(inmeasure(rowi,:),2);
        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
            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
            end
        end
    end

    if strcmp(g.plot_figs,'on')
        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);
    
    switch (critmethod);
        case 'fixed';
            colthresh=critvalue;
        case 'distrib'
            colthresh=mccritcol+sccritcol*critvalue;
    end
    
    colind=find(colcritcol>colthresh);
    
    if strcmp(g.plot_figs,'on')
        figure;
        subplot(3,3,[2,3,5,6]);surf(critcol,'LineStyle','none');
        axis('tight');
        view(0,90);
        
        subplot(3,3,[1,4]);plot(rowcritcol);
        axis('tight');
        view(270,90)
        
        subplot(3,3,[8,9]);plot(colcritcol);
        hold on;plot(ones(size(colcritcol))*colthresh,'r');
        axis('tight');
    end
end