Home > NoiseTools > nt_vecmult.m

nt_vecmult

PURPOSE ^

y=nt_vecmult(x,v) - multiply all rows or columns of matrix by vector

SYNOPSIS ^

function x=nt_vecmult(x,v)

DESCRIPTION ^

y=nt_vecmult(x,v) - multiply all rows or columns of matrix by vector

 See vecadd, bsxfun

 NoiseTools

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function x=nt_vecmult(x,v)
0002 %y=nt_vecmult(x,v) - multiply all rows or columns of matrix by vector
0003 %
0004 % See vecadd, bsxfun
0005 %
0006 % NoiseTools
0007 
0008 % check once and for all to save time
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     % same number of rows, v should be column vector (or same size as x)
0020     if nv==nn
0021         x=x.*v;
0022     elseif nv==1
0023         if bsxfun_exists;
0024             x=bsxfun(@times,x,v);
0025             %y=vecop_core(x, v, 1, 2);  % 2 is the opcode of multiplication in vecop_core
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     % same number of columns, v should be row vector (or same size as x)
0035     if mv==mm
0036         x=x.*v;
0037     elseif mv==1
0038         if bsxfun_exists;
0039             x=bsxfun(@times,x,v);
0040             %y=vecop_core(x, v, 2, 2);  % 2 is the opcode of multiplication in vecop_core
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

Generated on Sat 29-Apr-2023 17:15:46 by m2html © 2005