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:

- nt_fold y=fold(x,epochsize) - fold 2D to 3D
- nt_unfold y=nt_fold(x) - unfold 3D to 2D

This function is called by:

- nt_bias_fft [c0,c1]=nt_bias_fft(x,freq,nfft) - covariance with and w/o filter bias
- nt_cov [c,tw]=nt_cov(x,shifts,w) - time shift covariance
- nt_demean [y,mn]=nt_demean(x,w) - remove weighted mean over cols
- nt_multishift z=nt_multishift(x,shifts,amplitudes) - apply multiple shifts to matrix
- nt_normcol [y,norm]=nt_normcol(x,w) - normalize each column so its weighted msq is 1
- nt_regcov r=nt_regcov(cxy,cyy,keep,threshold) - regression matrix from cross covariance
- nt_sgram [s,f,t]=nt_sgram(x,window,noverlap,nfft,sr,flags) - spectrogram
- nt_sns y=nt_sns(x,nneigbors,skip,w) - sensor noise suppression
- nt_sns0 r=nt_sns0(c,nneigbors,skip,wc) - sensor noise suppression
- nt_tsxcov [c,tw]=nt_tsxcov(x,y,shifts,w) - cross-covariance of X and time-shifted Y
- nt_wpwr [y,tweight]=nt_wpwr(x,w) - weighted power
- nt_xcov [c,tw]=nt_xcov(x,y,shifts,w) - cross-covariance of X and time-shifted Y

## 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