Home > marsbar > @mardo_5 > private > pr_spm_vec.m

pr_spm_vec

PURPOSE ^

vectorises a numeric, cell or structure array

SYNOPSIS ^

function [vX] = pr_spm_vec(varargin)

DESCRIPTION ^

 vectorises a numeric, cell or structure array
 FORMAT [vX] = pr_spm_vec(X);
 X  - numeric, cell or stucture array[s]
 vX - vec(X)
__________________________________________________________________________

 e.g.:
 spm_vec({eye(2) 3}) = [1 0 0 1 3]'
__________________________________________________________________________
 Copyright (C) 2005 Wellcome Department of Imaging Neuroscience

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [vX] = pr_spm_vec(varargin)
0002 % vectorises a numeric, cell or structure array
0003 % FORMAT [vX] = pr_spm_vec(X);
0004 % X  - numeric, cell or stucture array[s]
0005 % vX - vec(X)
0006 %__________________________________________________________________________
0007 %
0008 % e.g.:
0009 % spm_vec({eye(2) 3}) = [1 0 0 1 3]'
0010 %__________________________________________________________________________
0011 % Copyright (C) 2005 Wellcome Department of Imaging Neuroscience
0012  
0013 % Karl Friston
0014 % $Id: spm_vec.m 279 2005-11-08 19:11:28Z karl $
0015 
0016 % initialise X and vX
0017 %--------------------------------------------------------------------------
0018 X     = varargin;
0019 if length(X) == 1
0020     X = X{1};
0021 end
0022 vX    = [];
0023 
0024 % vectorise structure into cell arrays
0025 %--------------------------------------------------------------------------
0026 if isstruct(X)
0027     f = fieldnames(X);
0028     X = X(:);
0029     for i = 1:length(f)
0030             vX = cat(1,vX,pr_spm_vec({X.(f{i})}));
0031     end
0032     return
0033 end
0034  
0035 % vectorise cells into numerical arrays
0036 %--------------------------------------------------------------------------
0037 if iscell(X)
0038     X     = X(:);
0039     for i = 1:length(X)
0040          vX = cat(1,vX,pr_spm_vec(X{i}));
0041     end
0042     return
0043 end
0044  
0045 % vectorise numerical arrays
0046 %--------------------------------------------------------------------------
0047 if isnumeric(X)
0048     vX = X(:);
0049 end
0050 

Generated on Wed 11-May-2022 16:26:09 by m2html © 2003-2019