-
Notifications
You must be signed in to change notification settings - Fork 1
/
checkSize2Analyze.m
110 lines (103 loc) · 4.18 KB
/
checkSize2Analyze.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
%% Analyze the data collected by checkSizeRun.
experiment='checkSize2';
if ~exist('skipDataCollection','var')
skipDataCollection=false;
end
if ~skipDataCollection
dataFolder=fullfile(fileparts(mfilename('fullpath')),'data');
cd(dataFolder);
matFiles=dir(fullfile(dataFolder,[experiment 'Run*.mat']));
clear data;
for i = 1:length(matFiles)
% Extract the desired fields into "data", one row per threshold.
d = load(matFiles(i).name);
data(i).LBackground=mean([d.cal.LFirst d.cal.LLast]); % Compute from cal in case it's not in o.
data(i).luminanceFactor=1; % default value
for field={'condition' 'experiment' 'dataFilename' 'experimenter' 'observer' 'trials' ...
'targetKind' 'targetGaborPhaseDeg' 'targetGaborCycles' ...
'targetHeightDeg' 'targetDurationSec' 'targetDurationSecMean'...
'targetCheckDeg' 'isTargetFullResolution' ...
'noiseType' 'noiseSD' 'noiseCheckDeg' ...
'eccentricityXYDeg' 'viewingDistanceCm' 'eyes' ...
'contrast' 'E' 'N' 'LBackground' 'conditionName'}
if isfield(d.o,field{:})
data(i).(field{:})=d.o.(field{:});
else
if i==1
warning OFF BACKTRACE
warning('Missing data field: %s\n',field{:});
end
end
end
end
if any([data(:).trials]<40)
s=sprintf('Threshold condition(trials):');
s=[s sprintf(' %d(%d),',data([data(:).trials]<40).condition,data([data(:).trials]<40).trials)];
warning('%d threshold(s) with fewer than 40 trials. %s',sum([data(:).trials]<40),s);
end
% data = data([data(:).trials]>=40); % Discard thresholds with less than 40 trials.
% Sort by condition
[~,ii]=sort([data(:).condition]);
data=data(ii);
fprintf('Plotting %d thresholds.\n',length(data));
end
assert(~isempty(data))
%% Compute derived quantities
for j=1:5:length(data)
for i=j:j+3
assert(data(j+4).N==0)
data(i).E0=data(j+4).E;
% (E-E0)/N
data(i).EE0N=(data(i).E-data(i).E0)/data(i).N;
% Neq=N E0/(E-E0)
data(i).Neq=data(i).N*data(i).E0/(data(i).E-data(i).E0);
data(i).targetCyclesPerDeg=data(i).targetGaborCycles/data(i).targetHeightDeg;
end
end
%% Create CSV file
t=struct2table(data);
spreadsheet=fullfile(fileparts(mfilename('fullpath')),'data',[experiment '.csv']);
writetable(t,spreadsheet);
t
fprintf('All selected fields have been saved in spreadsheet: \\data\\%s.csv\n',experiment);
fprintf('Please make a log-log plot of (E-E0)/N vs. noiseCheckDeg, with a line for each condition: isTargetFullResolution = 0 or 1\n');
%% Plot
figure;
set(gca,'FontSize',12);
clear legendString
for graph=1:2
ii=(graph-1)*5+(1:4);
i=ii(1);
loglog([data(ii).noiseCheckDeg],[data(ii).EE0N],'-x');
hold on;
legendString{graph}=sprintf('isTargetFullResolution %d',data(i).isTargetFullResolution);
if isfield(data(i),'conditionName') && ~isempty(data(i).conditionName)
legendString{graph}=[data(i).conditionName ': ' legendString{graph}];
end
end
hold off
legend(legendString);
legend('boxoff');
title(experiment);
xlabel('noiseCheckDeg');
ylabel('(E-E0)/N');
axis([0.01 1 1 100]); % Limits of x and y.
clear caption
caption{1}=sprintf('experimenter %s, observer %s,', ...
data(1).experimenter,data(1).observer);
caption{2}=sprintf('targetKind %s, noiseType %s', ...
data(1).targetKind,data(1).noiseType);
caption{3}=sprintf('eyes %s', data(1).eyes);
caption{4}=sprintf('%.1f c/deg, cosine phase',data(1).targetCyclesPerDeg);
annotation('textbox',[0.25 0.2 .1 .1],'String',caption,'FitBoxToText','on','LineStyle','none');
% pbaspect([1 1 1]); % Make vertical and horizontal axes equal in length.
% Scale so log units have same length vertically and horizontally.
xLimits = get(gca,'XLim');
yLimits = get(gca,'YLim');
yDecade = diff(yLimits)/diff(log10(yLimits)); %# Average y decade size
xDecade = diff(xLimits)/diff(log10(xLimits)); %# Average x decade size
set(gca,'XLim',xLimits,'YLim',yLimits,'DataAspectRatio',[1 yDecade/xDecade 1]);
% Save plot to disk
graphFile=fullfile(fileparts(mfilename('fullpath')),'data',[experiment '.eps']);
saveas(gcf,graphFile,'epsc')
% print(gcf,graphFile,'-depsc'); % equivalent to saveas above