help-octave
[Top][All Lists]
Advanced

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

Re: Vector approach to row margin frequencies


From: Judd Storrs
Subject: Re: Vector approach to row margin frequencies
Date: Tue, 23 Jun 2009 20:12:24 -0400

Sorry, I messed that up. It should have been @rdivide in the previous mail. You can actually use either @ldivide or @rdivide but I had the order incorrect for @ldivide. Sorry. The correct versions are:

Y1 = X ./ repmat(sum(X,2),[1 columns(X)]);
Y2 = bsxfun(@times,X,1./sum(X,2));
Y3 = bsxfun(@rdivide,X,sum(X,2))
Y4 = bsxfun(@ldivide,sum(X,2),X)

For some reason the bxsfun runs are faster from inside a m-script than directly on the command line (3.0.1 maybe different in 3.2).

--judd


On Tue, Jun 23, 2009 at 8:02 PM, Judd Storrs <address@hidden> wrote:


On Tue, Jun 23, 2009 at 7:40 PM, Judd Storrs <address@hidden> wrote:
On Tue, Jun 23, 2009 at 6:39 PM, ws <address@hidden> wrote:
I would love to now get the row frequencies avoiding a while loop, something
like F=X./S, but that doesn't work (though it seems somehow consistent -- I
realize that we don't recycle vectors in Octave/ Mat* ) ....

Are trying to divide each row by its sum? I think the bsxfun will do this:

bsxfun(@times,X,1./S)

I'm not sure if there is a direct function name for "./". If you can figure that out you can also avoid the separate division.

--judd



I found it. It's @ldivide

tic
Y1 = X ./ repmat(sum(X,2),[1 columns(X)]);
toc
Elapsed time is 0.02987 seconds.

tic
Y2 = bsxfun(@times,X,1./sum(X,2));
toc
Elapsed time is 0.0077 seconds.

tic
Y3 = bsxfun(@rdivide,X,sum(X,2));
toc
Elapsed time is 0.0002439 seconds.

--judd



reply via email to

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