[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Subtracting vectors from matrices
From: |
Stefan van der Walt |
Subject: |
Re: Subtracting vectors from matrices |
Date: |
Wed, 17 Nov 2004 00:54:56 +0200 |
User-agent: |
Mutt/1.5.6+20040722i |
Hi Ryan
Would "repmat" solve your problem?
Regards
Stefan
On Tue, Nov 16, 2004 at 11:18:42AM -0600, Ryan Peterson wrote:
> Hi all, this is my first time posting to the helplist so don't lynch me if
> this is either trivial or something inappropriate for the helplist... with
> that said...
>
> Has anyone done any work on overloading the addition or subtraction
> functions so that one might add a column vector to each column in a larger
> matrix?
>
> Currently my sample code looks like this:
>
> r=rand(3,3);
> pnts=rand(3,100000);
> tic;
> rotpnts=r*pnts;
> ###method 1
> diffx=rotpnts(1,:)-rotpnts(1,1);
> diffy=rotpnts(2,:)-rotpnts(2,1);
> diffz=rotpnts(3,:)-rotpnts(3,1);
> ###method 2 - for a taste of what the speed could be.
> # diff=rotpnts-rotpnts(1,1);
> toc
>
> I would have guessed that the major time cost would have been in the matrix
> multiplication,
> but 1 run of it shows the subtraction routines take more than ten times
> longer to run than the matrix in multiplication (in method 1). Just
> subtracting a scalar (as in method 2) takes around 1/4th as long as the
> matrix multiplication (~40X faster overall). It would be nice if something
> like
> diff=rotpnts-rotpnts(1:3,1) would work in some way (maybe through a special
> function call). Does anyone have experience with this?
>
> I realize there are probably other ways to do what I'm ultimately exploring
> for my own amusement, but this seems like a feature that might be useful to
> others?
>
> Any suggestions?
>
> Thanks in advance,
> Ryan Peterson
-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.
Octave's home on the web: http://www.octave.org
How to fund new projects: http://www.octave.org/funding.html
Subscription information: http://www.octave.org/archive.html
-------------------------------------------------------------