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

pr_spm_unvec

PURPOSE ^

unvectorises a vectorised array

SYNOPSIS ^

function [varargout] = pr_spm_unvec(vX,varargin)

DESCRIPTION ^

 unvectorises a vectorised array
 FORMAT [X] = pr_spm_unvec(vX,X);
 X  - numeric, cell or stucture array
 vX - pr_spm_vec(X)

 i.e. X      = pr_spm_unvec(pr_spm_vec(X),X)
      [X{:}] = pr_spm_unvec(pr_spm_vec(X{:}),X{:})
                                              - (i.e. can also deal)

 see pr_spm_vec
__________________________________________________________________________
 Copyright (C) 2005 Wellcome Department of Imaging Neuroscience

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [varargout] = pr_spm_unvec(vX,varargin)
0002 % unvectorises a vectorised array
0003 % FORMAT [X] = pr_spm_unvec(vX,X);
0004 % X  - numeric, cell or stucture array
0005 % vX - pr_spm_vec(X)
0006 %
0007 % i.e. X      = pr_spm_unvec(pr_spm_vec(X),X)
0008 %      [X{:}] = pr_spm_unvec(pr_spm_vec(X{:}),X{:})
0009 %                                              - (i.e. can also deal)
0010 %
0011 % see pr_spm_vec
0012 %__________________________________________________________________________
0013 % Copyright (C) 2005 Wellcome Department of Imaging Neuroscience
0014 
0015 % Karl Friston
0016 % $Id: spm_vec.m 184 2005-05-31 13:23:32Z karl $
0017 
0018 % deal to multiple outputs if necessary
0019 %--------------------------------------------------------------------------
0020 if nargout > 1
0021     varargout = pr_spm_unvec(vX,varargin);
0022     return
0023 end
0024 if length(varargin) == 1
0025     X = varargin{1};
0026 else
0027     X = varargin;
0028 end
0029 
0030 % fill in structure arrays
0031 %--------------------------------------------------------------------------
0032 if isstruct(X)
0033     f = fieldnames(X);
0034     for i = 1:length(f)
0035         c          = {X.(f{i})};
0036         n          = length(pr_spm_vec(c));
0037         c          = pr_spm_unvec(vX(1:n),c);
0038         [X.(f{i})] = deal(c{:});
0039         vX         = vX(n + 1:end);
0040     end
0041     varargout      = {X};
0042     return
0043 end
0044 
0045 % fill in cells arrays
0046 %--------------------------------------------------------------------------
0047 if iscell(X)
0048     for i = 1:length(X(:))
0049         n     = length(pr_spm_vec(X{i}));
0050         X{i}  = pr_spm_unvec(vX(1:n),X{i});
0051         vX    = vX(n + 1:end);
0052     end
0053     varargout      = {X};
0054     return
0055 end
0056 
0057 % reshape numerical arrays
0058 %--------------------------------------------------------------------------
0059 if isnumeric(X)
0060     X(:)  = vX;
0061 else
0062     X     = [];
0063 end
0064 varargout = {X};

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