-
Notifications
You must be signed in to change notification settings - Fork 6
/
mat_to_cmu.m
executable file
·37 lines (32 loc) · 1.12 KB
/
mat_to_cmu.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
function[data, meta] = mat_to_cmu(mat)
%MAT_TO_CMU convert image(s) in matrix format to CMU format
%
% Usage: [data, meta] = mat_to_cmu(mat)
%
% INPUTS:
% mat: a 4D matrix of brain images.
%
% OUTPUTS:
% data: a cell array containing vectors of voxel activations.
%
% meta: a struct with the following fields:
% nvoxels: total number of voxels containing brain
% coordToCol: dimx by dimy by dimz matrix of voxel numbers (zeros
% indicate no voxel at the corresponding location)
% colToCoord: nvoxels by 3 matrix of voxel locations
%
%
%
% SEE ALSO: CMU_TO_MAT, CONSTRUCT_META, PLOT_BRAIN2D, PLOT_BRAIN3D, SLICES, CAT
%
% AUTHOR: Jeremy R. Manning
% CONTACT: [email protected]
% CHANGELOG:
% 12-11-13 jrm wrote it.
sliced_mats = slices(mat, ndims(mat));
meta = construct_meta(size(sliced_mats{1}));
data = cellfun(@(x)(x(:)'), sliced_mats, 'UniformOutput', false);
good_inds = ~isnan(mean(mat, ndims(mat)));
good_inds = good_inds(:)';
meta = meta_select_voxels(meta, find(good_inds));
data = cellfun(@(x)(x(good_inds)), data, 'UniformOutput', false);