forked from LIMO-EEG-Toolbox/limo_tools
-
Notifications
You must be signed in to change notification settings - Fork 1
/
limo_add_plots.m
219 lines (198 loc) · 7.08 KB
/
limo_add_plots.m
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
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
function limo_add_plots
% interactive ploting functon for data generated by
% limo_central_tendency_and_ci or any data in 4D with dim channel
% * time * conditions * 3 with this last dim being the low end of the
% confdidence interval, the estimator (like eg mean), high end of the
% confidence interval and the variable is called M, TM, Med or HD
out = 0;
turn = 1;
current = pwd;
subjects_plot = 0;
electrode = [];
while out == 0
%% Data selection
% ------------------
[file,path,index]=uigetfile('*mat',['Select Central tendency file n:' num2str(turn) '']);
if index == 0
out = 1; return
else
data = load(sprintf('%s%s',path,file));
data = getfield(data,cell2mat(fieldnames(data)));
% the last dim of data.xxx if 3 (low CI, estimator, high CI)
if isfield(data,'mean')
name{turn} = 'Mean';
tmp = data.mean;
elseif isfield(data,'trimmed_mean')
name{turn} = 'Trimmed Mean';
tmp = data.trimmed_mean;
elseif isfield(data,'median')
name{turn} = 'Median';
tmp = data.median;
elseif isfield(data,'Harrell_Davis')
name{turn} = 'Harrell-Davis';
tmp = data.Harrell_Davis;
% the last dim of data.data is the number of subjects or the trials
% sorted by there weights (dim=10) ; figure case using file name
elseif isfield(data,'data')
if ~isempty(strfind(file, 'Mean'))
name{turn} = 'Subjects'' Means';
elseif ~isempty(strfind(file, 'Trimmed mean'))
name{turn} = 'Subjects'' Trimmed Means';
elseif ~isempty(strfind(file, 'HD'))
name{turn} = 'Subjects'' Mid Deciles HD';
elseif ~isempty(strfind(file, 'Median'))
name{turn} = 'Subjects'' Medians';
else
if strcmpi(file,'subjects_weighted_data.mat')
name{turn} = 'Data plotted per weight';
else
underscores = strfind(file, '_');
if ~isempty(underscores)
file(underscores) = ' ';
end
ext = strfind(file, '.');
file(max(ext):end) = [];
name{turn} = file;
end
end
subjects_plot = 1;
tmp = data.data;
else
errordlg2('unknown file format');
return
end
end
limo = data.limo;
clear data
if size(tmp,1) == 1 && size(tmp,3) == 1% only 1 channel and 1 variable
D = squeeze(tmp(:,:,1,:));
Data = nan(1,size(tmp,2),size(tmp,4));
Data(1,:,:) = D; clear D;
elseif size(tmp,1) > 1 && size(tmp,3) == 1 % only 1 variable
Data = squeeze(tmp(:,:,1,:));
else
if subjects_plot == 1
v = inputdlg(['which subject to plot, 1 to ' num2str(size(tmp,3))],'plotting option');
else
v = inputdlg(['which variable to plot, 1 to ' num2str(size(tmp,3))],'plotting option');
end
if isempty(v)
out = 1; return
elseif strcmp(v,'mean')
Data = squeeze(nanmean(tmp,3));
else
try
v = str2num(cell2mat(v));
catch
v = eval(cell2mat(v));
end
if length(v)>1
errordlg2('only 1 parameter value expected')
else
if size(tmp,1) == 1 && size(tmp,3) > 1
D = squeeze(tmp(:,:,v,:));
Data = nan(1,size(tmp,2),size(tmp,4));
Data(1,:,:) = D; clear D;
else
Data = squeeze(tmp(:,:,v,:));
end
end
end
end
clear tmp
%% prep figure the 1st time rounnd
% ------------------------------
if turn == 1
plotfig = figure('Name','Central Tendency Estimate','color','w'); hold on
% timing info
% ----------
try
timevect = limo.data.start:(1000/limo.data.sampling_rate):limo.data.end; % in msec
catch
v = inputdlg('enter time interval by hand e.g. [0:0.5:200]');
if isempty(v)
return
else
try
timevect = eval(cell2mat(v));
if length(timevect) ~= size(Data,2)
disp('time interval invalid format');
timevect = 1:size(Data,2);
end
catch ME
disp('time interval invalid format');
timevect = 1:size(Data,2);
end
end
end
end
%% electrode to plot
% ----------------
if size(Data,1) == 1
Data = squeeze(Data(1,:,:)); toplot = [];
else
if isempty(electrode)
electrode = inputdlg(['which electrode top plot 1 to' num2str(size(Data,1))],'electrode choice');
end
if strcmp(electrode,'')
tmp = Data(:,:,2);
if abs(max(tmp(:))) > abs(min(tmp(:)))
[electrode,~,~] = ind2sub(size(tmp),find(tmp==max(tmp(:))));
else
[electrode,~,~] = ind2sub(size(tmp),find(tmp==min(tmp(:))));
end
if length(electrode) ~= 1; electrode = electrode(1); end;
Data = squeeze(Data(electrode,:,:)); fprintf('ploting channel %g\n',electrode)
else
try
Data = squeeze(Data(electrode,:,:));
catch
Data = squeeze(Data(eval(cell2mat(electrode)),:,:));
end
end
end
% finally plot
% ---------------
if turn==1
if subjects_plot == 1
plot(timevect,Data,'LineWidth',2);
assignin('base','plotted_data',Data)
else
plot(timevect,Data(:,2)','LineWidth',3);
assignin('base','plotted_data',Data(:,2)')
end
colorOrder = get(gca, 'ColorOrder');
colorindex = 1;
else
plot(timevect,Data(:,2)','Color',colorOrder(colorindex,:),'LineWidth',3);
assignin('base','plotted_data',Data(:,2)')
end
if subjects_plot == 0
fillhandle = patch([timevect fliplr(timevect)], [Data(:,1)',fliplr(Data(:,3)')], colorOrder(colorindex,:));
set(fillhandle,'EdgeColor',colorOrder(colorindex,:),'FaceAlpha',0.2,'EdgeAlpha',0.8);%set edge color
end
grid on; axis tight; box on;
xlabel('Time ','FontSize',14)
ylabel('Amplitude','FontSize',14)
if turn == 1
mytitle = name{1};
else
mytitle = sprintf('%s & %s',mytitle,name{turn});
end
if iscell(electrode)
electrode = eval(cell2mat(electrode));
end
title(sprintf('electrode %g \n %s',electrode,mytitle),'Fontsize',16);
% updates
turn = turn+1;
if colorindex <7
colorindex = colorindex + 1;
else
colorindex = 1;
end
if subjects_plot == 1;
out =1; return;
else
pause(1);
end
end