help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Applying each element of a vector to each row of a matrix


From: Judd Storrs
Subject: Re: Applying each element of a vector to each row of a matrix
Date: Sun, 19 Dec 2010 20:06:36 -0500

The bsxfun function does a lot of this. Assume

a = ones(10) ;
v = 1:10 ;

Multiply each column of a by the corresponding element of v:

bsxfun(@times, a, v)

Multiply each row of a by the corresponding element of v:

bsxfun(@times, a, v')

Raise each column of a to the corresponding power of v:

bsxfun(@power, a, v)

Raise each row of a to the corresponding power of v:

bsxfun(@power, a, v')


--judd


reply via email to

[Prev in Thread] Current Thread [Next in Thread]