forked from cab79/Matlab_files
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot_topo.m
More file actions
119 lines (107 loc) · 3.32 KB
/
plot_topo.m
File metadata and controls
119 lines (107 loc) · 3.32 KB
1
2
3
4
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
76
77
78
79
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
function plot_topo(P,D,cmap)
% requires:
% D.DAT (output from plotprepare_)
% P.WFrows
% P.Nplots
% P.Fi_ind
% P.fi
% P.cond
% P.chanlocs
% P.Eval
% P.EEGtimes
% average ERPs over non-unique rows
ind = unique(D.WFrows,'stable')';
DATa = cell(length(ind),1);
for i = ind
DATa{i}=mean(cat(3,D.DAT{D.WFrows==i}),3);
end
f1=figure
pln=0;
if isfield(P,'selectlev')
D.Fi_ind = find(D.Fi(:,1)==P.selectlev); % indices of Fi (and wf) for each plot
%else
% D.Fi_ind = find(D.Fi(:,1)); % indices of Fi (and wf) for each plot
end
y=DATa(D.Fi_ind);
y=y(D.fi);
if iscell(P.cval)
cond = P.cval{1}(P.cval{2});
condind=nan(1,length(D.cond));
for cn = 1:length(cond)
ind = ismember(D.cond,cond{cn});
condind(ind) = cn;
end
else
[cond,~,condind]=unique(D.cond,'stable');
unicond = unique(condind)';
end
% gather data
plotchans=1:length(D.chanlocs);
plotchans(P.no_plot_ele)=[];
dat=struct;
if P.sub_order == 1
plotorder = 1:length(cond);
else
plotorder = length(cond):-1:1;
end
for cn = plotorder
peakdata=y(condind==cn);
peakdata = mean(cat(3,peakdata{:}),3);
%[~,markchans] = intersect(plotchans,tp);
if any(P.topo_subtimewin) && length(P.topo_subtimewin)==1 % multiple plots within a range
cluswin = D.E_val(end)-D.E_val(1);
nlat = floor(cluswin/P.topo_subtimewin);
if nlat>1
lats = linspace(D.E_val(1),D.E_val(end),nlat);
lats = dsearchn(D.EEGtimes',lats');
else
lats = [find(D.EEGtimes==D.E_val(1)) find(D.EEGtimes==D.E_val(end))];
end
for ln = 1:length(lats)-1
pln = pln+1;
lat=lats(ln:ln+1);
dat(pln).peakdata = mean(peakdata(:,min(lat):max(lat)),2);
ax(pln) = subplot(length(cond),length(lats)-1,pln);
end
elseif any(P.topo_subtimewin) && length(P.topo_subtimewin)==2 % specified time window
pln = pln+1;
lat = dsearchn(D.EEGtimes',P.topo_subtimewin');
dat(pln).peakdata = mean(peakdata(:,min(lat):max(lat)),2);
ax(pln) = subplot(length(unicond),1,pln);
else
pln = pln+1;
lat = find(D.EEGtimes==D.E_val(1));
dat(pln).peakdata = mean(peakdata(:,min(lat):max(lat)),2);
ax(pln) = subplot(length(unicond),1,pln);
end
%title(num2str(D.EEGtimes(lat)),'fontsize',P.fontsize)
end
% equate scales
alldat=[dat(:).peakdata];
plotmin = min(alldat(:));
plotmax = max(alldat(:));
plotchans=1:length(D.chanlocs);
plotchans(P.no_plot_ele)=[];
for pln = 1:length(dat)
axes(ax(pln))
plottopotype(dat(pln).peakdata,D.chanlocs,plotchans,P.topotype,[plotmin plotmax],cmap)
end
linkaxes(ax,'xy')
end
function plottopotype(dat,chanlocs,plotchans,topotype,minmax,cmap)
switch topotype
case 'eeglab'
topoplot(dat, chanlocs,'maplimits',minmax,'plotchans',plotchans,'electrodes','off','style','map','intrad',0.55,'colormap',cmap);%,'emarker2',{markchans,'o','w',7,1});
case 'pcolor' % UNFINISHED
topo = nanmean(R(f2).Vdv(:,:,tw),3);
figure
set(gcf, 'Position', [400, 400, 350, 300])
%imagesc(rot90(topo))
pcolor(rot90(topo,3)), shading interp
axis off
colormap(jet)
title([field{f} ': time of max ' field{f2} ' for image ' num2str(xval_peak) 'ms'])
colorbar
end
%tightfig(f1)
end