-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetFolderTrialsStatistics.m
More file actions
88 lines (71 loc) · 2.25 KB
/
Copy pathgetFolderTrialsStatistics.m
File metadata and controls
88 lines (71 loc) · 2.25 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
function [N, XAXIS, NAMES] = getFolderTrialsStatistics(cfg)
% getFolderTrialsStatistics uses getTrialsStatistics to plot histogram of
% trials lengths for all patients in cfg.inputDir.
%
% cfg.inputDir
% cfg.type (condition type, e.g. R)
% cfg.eyes (O, C, U)
%
% e.g.
% cfg =[];
% cfg.inputDir = 'C:\Users\Roey\Documents\Lab\PNES Project\LongSegments';
% cfg.type = {'P'};
% cfg.eyes = {'O', 'C', 'U'};
% [N, XAXIS, NAMES] = getFolderTrialsStatistics(cfg)
inputDir = cfg.inputDir;
type = cfg.type ;
eyes = cfg.eyes;
minTime = 0;
maxTime = inf;
split = 0;
outputName = 'Temp';
noInterpolatedNeighbours = 'yes';
files = getfullfiles([inputDir, filesep, '*.mat']);
N = cell(length(files),1);
XAXIS = cell(length(files),1);
NAMES = cell(length(files),1);
maxX = 0;
minX = [];
for fileI = 1:length(files)
[~, NAMES{fileI}] = fileparts(files{fileI});
flag = query (NAMES(fileI), inputDir, type, eyes, 'A' , minTime, maxTime, split, noInterpolatedNeighbours, outputName);
if flag == 0
N{fileI} = 0;
XAXIS{fileI} = 0;
continue
end
data = load2struct([inputDir, filesep, 'queries', filesep, outputName, '.mat']);
trialsLengths = zeros(1,length(data.time));
for j = 1:length(data.time)
trialsLengths(j) = size(data.time{j},2);
end
trialsLengths = trialsLengths./(data.fsample);
[nTemp, xTemp] = hist(trialsLengths);
xTemp = floor(xTemp);
XAXIS{fileI} = unique(xTemp); % in integer seconds
for i = 1:length(XAXIS{fileI})
indices = (xTemp == XAXIS{fileI}(i));
N{fileI}(i) = sum(nTemp.*indices);
end
maxX = max( maxX, max(XAXIS{fileI}) );
if isempty(minX)
minX = min(XAXIS{fileI});
end
minX = min( minX, min(XAXIS{fileI}) );
end
%% Plot Results
XAXIS4plot = minX:1:maxX;
N4plot = zeros(length(files),length(XAXIS4plot));
for fileI = 1:length(files)
for xVal = 1:length(XAXIS{fileI})
index = find(XAXIS4plot == XAXIS{fileI}(xVal))
N4plot(fileI,index) = N{fileI}(xVal);
end
end
figure;
bar(XAXIS4plot, N4plot', 'grouped');
title(['Condition ' type ' ' eyes]);
legend(NAMES{:})
ylabel('# of trials');
xlabel('time (s)');
end