0001 function x=nt_vecmult(x,v)
0002
0003
0004
0005
0006
0007
0008
0009 persistent bsxfun_exists;
0010 if isempty(bsxfun_exists); bsxfun_exists=(exist('bsxfun')==5); end
0011
0012 [m,n,o]=size(x);
0013 x=nt_unfold(x);
0014 v=nt_unfold(v);
0015
0016 [mm,nn]=size(x);
0017 [mv,nv]=size(v);
0018 if mv==mm
0019
0020 if nv==nn
0021 x=x.*v;
0022 elseif nv==1
0023 if bsxfun_exists;
0024 x=bsxfun(@times,x,v);
0025
0026 else
0027 x=x .* repmat(v,1,nn);
0028 end
0029 else
0030 error('V should be row vector');
0031 end
0032
0033 elseif nv==nn
0034
0035 if mv==mm
0036 x=x.*v;
0037 elseif mv==1
0038 if bsxfun_exists;
0039 x=bsxfun(@times,x,v);
0040
0041 else
0042 x=x .* repmat(v,mm,1);
0043 end
0044 else
0045 error('V should be column vector');
0046 end
0047
0048 else
0049 error('V and X should have same number of rows or columns');
0050 end
0051
0052 x=nt_fold(x,m);
0053