-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgetVarsFromStimvol.m
112 lines (90 loc) · 2.9 KB
/
getVarsFromStimvol.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
%getVarsFromStimvol.m
%
%
% author: steeve laquitaine
% date: 160112
%purpose: retrieve variables associated with instances using stimvols
% (from getStimvol)
%
%usage:
%
%e.g.,
%
% %set params
% o.sessPath = '~/data/datafMRI/sltaskdotdirfmri05/s02520150814';
% o.myGroup = 'Concatenation';
% o.myScan = 1;
% o.taskNum = 2;
% o.phaseNum = 1;
% o.segmentNum = 2;
% variables = {'myRandomDir','myRandomCoh'};
%
% %get stimvols you want variables of
% cd(o.sessPath)
% v = mrLoadRet([]);
% v = viewSet(v,'curGroup',o.myGroup,'curScan',o.myScan);;
% stimvols = getStimvol(v,'myRandomCoh','taskNum',o.taskNum,'phaseNum',...
% o.phaseNum,'segmentNum',o.segmentNum);
%
% %get variable values associated with stimvols
% [vars,o,db] = getVarsFromStimvol(stimvols,variables,o)
%
%
%inputs:
% stimvols: input stimvols
% variables: variable values we want for stimvols
% o: fmri session parameters
%
%output:
% vars: variables associated with stimvols
% db: sorted variables and stimvols
% o: parameters
function [vars,o,db] = getVarsFromStimvol(stimvols,variables,o)
%open session
cd(o.sessPath)
v = mrLoadRet([]);
%set group & scan
v = viewSet(v,'curGroup',o.myGroup);
v = viewSet(v,'curScan',o.myScan);
%get all stimvols and variables
[d,o.variables] = getStimvol(v,variables,'taskNum',o.taskNum,'phaseNum',...
o.phaseNum,'segmentNum',o.segmentNum);
nCond = length(o.variables);
j = zeros(1,nCond);
for ivar = 1 : length(variables)
%init variable values
db.(variables{ivar}) = [];
%get variable
a = regexp(o.variables,variables{ivar});
%find variable values
thisVarpos = find(~cellfun('isempty',a));
%get variable values
nValueThisVar = length(thisVarpos);
for k = 1 : nValueThisVar
%get trial #
valPos = thisVarpos(k);
volsThisVarValue = d{valPos};
nTrialsThisVar = length(volsThisVarValue);
%get this variable value
thisVarValue = o.variables{valPos};
posValue = regexp(thisVarValue,variables{ivar},'end')+2;
valThisVar = str2double(thisVarValue(posValue:end));
%add to previous values
db.(variables{ivar}) = [db.(variables{ivar}); repmat(valThisVar,nTrialsThisVar,1)];
end
%get and sort stimvols matched with associated variables
db.stimvols = cell2mat(d(thisVarpos));
[db.stimvols,sorted] = sort(db.stimvols);
db.(variables{ivar}) = db.(variables{ivar})(sorted);
end
%retrieve input stimvols variables
o.stimvols = stimvols;
for i = 1 : length(stimvols)
%find stimvols in db
[~,volsPos] = intersect(db.stimvols,stimvols{i});
%get corresponding variables
for ivar = 1 : length(variables)
vars.(variables{ivar}){i} = db.(variables{ivar})(volsPos);
end
end
mrQuit