-
Notifications
You must be signed in to change notification settings - Fork 0
/
mT_retrieveSimParams.m
50 lines (39 loc) · 1.62 KB
/
mT_retrieveSimParams.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
function SimParams = mT_retrieveSimParams(DSet, ptpnt)
% Find the parameters used to simulate data.
% INPUT
% ptpnt: Participant number or string. If number the parameters used for
% the corresponding participant are retrieved. If string is 'average', the
% average parameters across participants are retrieved. If string is 'stack'
% the parameters from all participants are stacked along the first unused
% dimention of the array in each field of DSet.P(i).Sim.Params
% HISTORY
% Reviewed 2020
% Check same parameters applied to all participants
params = fieldnames(DSet.P(1).Sim.Params);
for iP = 2 : length(DSet.P)
if ~isequal(params, fieldnames(DSet.P(iP).Sim.Params))
error('Bug')
end
end
if isnumeric(ptpnt)
SimParams = DSet.P(ptpnt).Sim.Params;
elseif strcmp(ptpnt, 'average') || strcmp(ptpnt, 'stack')
% Loop through params averaging across participants
for iParam = 1 : length(params)
allPtpntParams = mT_stackData( ...
DSet.P, @(struc) struc.Sim.Params.(params{iParam}));
% mT_stackData stacks along the first unused dimention greater than 1
finalDimention = length(size(allPtpntParams));
if size(allPtpntParams, finalDimention) ~= length(DSet.P)
error('Bug')
end
% Average along the stack dimention (across participants) if requested
if strcmp(ptpnt, 'stack')
SimParams.(params{iParam}) = allPtpntParams;
elseif strcmp(ptpnt, 'average')
SimParams.(params{iParam}) = mean(allPtpntParams, finalDimention);
end
end
else
error('Unknown option')
end