-
Notifications
You must be signed in to change notification settings - Fork 1
/
GLMinVOI.m
58 lines (45 loc) · 1.78 KB
/
GLMinVOI.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
function [b] = GLMinVOI(glm, voi, voiNum)
% [b] = GLMinVOI(glm, voi ,voiNum)
%
% Inputs:
% glm As given by glm = BVQXfile(glmPath)
% voi As given by voi = BVQXfile(voiPath)
% voiNum Index number (or range) of the voi(s) to be indexed
% (default: 1:length(voi.VOI))
%
% Output:
% b A structure containing glm indices and data with fields:
% id Linear indices of voi used for the glm matrix
% beta A [nVoxel nPredictors] matrix of beta weights within the
% roi
% Written by Kelly Chang - October 10, 2016
%% Input Control
if ~exist('voiNum', 'var')
voiNum = 1:length(voi.VOI);
end
%% Start Extracting Beta Weights
% glm size and relative position (offset) within vmr volume
glmData = glm.GLMData.BetaMaps;
glmSize = size(glmData);
glmOffset = [glm.XStart glm.YStart glm.ZStart];
for i = voiNum
% voi coordinates in anatomical resolution
v = voi.BVCoords(i);
% convert voi coordinates to vtc coordinates and resolution
v = round(bsxfun(@minus, v, glmOffset)/glm.Resolution) + 1;
% take only voi voxels inside the vtc volume
indx = (v(:,1) > 0 & v(:,1) <= glmSize(1) & ...
v(:,2) > 0 & v(:,2) <= glmSize(2) & ...
v(:,3) > 0 & v(:,3) <= glmSize(3));
v = v(indx,:);
% transform voi [x y z] coordinates into linear index equivalents
v = sub2ind(glmSize(1:3), v(:,1), v(:,2), v(:,3));
% name of the roi
b(i).name = voi.VOI(i).Name;
% only keep the unique indices
b(i).id = unique(v);
% reshape vtc data into linear space
glmData = reshape(glmData, [prod(glmSize(1:3)) glmSize(4)]);
% take only vtc data inside voi voxels in linear space
b(i).beta = glmData(b(i).id,:);
end