0001 function x=nt_vecadd(x,v)
0002
0003
0004
0005
0006
0007
0008
0009 persistent bsxfun_exists;
0010 if isempty(bsxfun_exists);
0011 bsxfun_exists=(exist('bsxfun')==5);
0012 if ~bsxfun_exists;
0013 warning('bsxfun not found. Using repmat');
0014 end
0015 end
0016
0017
0018 [m,n,o]=size(x);
0019 x=nt_unfold(x);
0020 v=nt_unfold(v);
0021
0022 [mm,nn]=size(x);
0023 if numel(v)==1;
0024 x=x+v;
0025 elseif size(v,1)==1
0026 if size(v,2)~=nn; error('V should have same number of columns as X'); end
0027 if bsxfun_exists;
0028 x=bsxfun(@plus,x,v);
0029
0030 else
0031 x=x + repmat(v,mm,1);
0032 end
0033 elseif size(v,2)==1
0034 if size(v,1)~=mm; error('V should have same number of rows as X'); end
0035 if bsxfun_exists;
0036 x=bsxfun(@plus,x,v);
0037
0038 else
0039 x=x + repmat(v,1,nn);
0040 end
0041 end
0042
0043 x=nt_fold(x,m);