-
Notifications
You must be signed in to change notification settings - Fork 3
/
spm_vec.m
57 lines (49 loc) · 1.51 KB
/
spm_vec.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
function [vX] = spm_vec(X,varargin)
% Vectorise a numeric, cell or structure array - a compiled routine
% FORMAT [vX] = spm_vec(X)
% X - numeric, cell or stucture array[s]
% vX - vec(X)
%
% See spm_unvec
%__________________________________________________________________________
%
% e.g.:
% spm_vec({eye(2) 3}) = [1 0 0 1 3]'
%__________________________________________________________________________
% Copyright (C) 2005-2013 Wellcome Trust Centre for Neuroimaging
% Karl Friston
% $Id: spm_vec.m 6110 2014-07-21 09:36:13Z karl $
# SPDX-License-Identifier: GPL-2.0
%error('spm_vec.c not compiled - see Makefile')
% initialise X and vX
%--------------------------------------------------------------------------
if nargin > 1
X = [{X},varargin];
end
% vectorise numerical arrays
%--------------------------------------------------------------------------
if isnumeric(X)
vX = X(:);
% vectorise logical arrays
%--------------------------------------------------------------------------
elseif islogical(X)
vX = X(:);
% vectorise structure into cell arrays
%--------------------------------------------------------------------------
elseif isstruct(X)
vX = [];
f = fieldnames(X);
X = X(:);
for i = 1:numel(f)
vX = cat(1,vX,spm_vec({X.(f{i})}));
end
% vectorise cells into numerical arrays
%--------------------------------------------------------------------------
elseif iscell(X)
vX = [];
for i = 1:numel(X)
vX = cat(1,vX,spm_vec(X{i}));
end
else
vX = [];
end