Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: Multiplying each colum of my matrix by a constant
Replies: 13   Last Post: Jun 15, 2013 3:54 AM

 Messages: [ Previous | Next ]
 Wanderson Posts: 25 Registered: 10/3/11
Re: Multiplying each colum of my matrix by a constant
Posted: Jun 12, 2013 10:47 AM

"Wanderson " <wanderson.ferreira@usp.br> wrote in message <kpa06k\$hij\$1@newscl01ah.mathworks.com>...
> dpb <none@non.net> wrote in message <kp9vn3\$v42\$1@speranza.aioe.org>...
> > On 6/11/2013 6:49 PM, dpb wrote:
> > > On 6/11/2013 6:00 PM, Wanderson wrote:
> > >> dpb <none@non.net> wrote in message <kp89gu\$ooe\$1@speranza.aioe.org>...
> > > ...
> > >

> > >>> If you need speed, the straight-ahead loop is probably as good as
> > >>> you're going to do w/o a specialized mex function. (I believe there
> > >>> may be some submissions on File Exchange that do, in fact, promise
> > >>> better performance than bsxfun iirc)
> > >>>
> > >>> --

> > >>
> > >> hehe, my problem is that I am doing a program that evaluates some double
> > >> integrals, calculate FFT and whanever, but I have a NECESSARY big 'FOR
> > >> LOOP' inside my program to store each value of these integrals in the
> > >> right place. And I didn't want to use another loop inside my huge loop
> > >> rsrsrs.

> > >
> > > For 3x3 you can always try the explicit repmat() route, too for
> > > comparative timings...
> > >
> > > m.*repmat(v,size(m,1),1)
> > >
> > > And, of course, if you're lucky enough that the v is a constant you
> > > could obviously save it since memory isn't going to be an issue.
> > >
> > > bsxfun() is essentially syntactic candy to save explicitly writing such
> > > as the above but is basically all it is. Of course, it has the overhead
> > > of processing inputs and all that. I've not tested but I'd suspect the
> > > time differential would drop pretty quickly w/ size of the arrays as
> > > compared to other implementation choices.
> > >

> >
> > BTW...
> >
> > If the object is speed in an inner loop, then for the 3x3 case the
> > original version of writing out the three explicit multiplies may well
> > be the most efficacious route. For higher dimensions it gets klunky
> > certainly but for as few as three it's not so bad.
> >
> > --

>
>
> Thanks again dpb,
> In fact, my matrices dimensions vary inside my program rsrs.
> I start with an 3x3 matrix and they will growing as (2k+1) x (2k+1) dimension.
> I'll try the repmat idea, this function seems to be very usefull to many things, I should learn more about it.

BTW[2] rsrs

I just implemented the repmat solution in my code, but it is slower than the bsxfun() option.
I did the test using the same parameters inside my program and I found this:
Using bsxfun() my program took 13 second to complete.
Using repmat() my program took 20 second to complete.

It is a huge difference to me, because I need to run it several times, as I said before, and 7 second every time that I run the code, is a lot of thing.

But thx, I'm learning a lot with this things. :)

Date Subject Author
6/11/13 Wanderson
6/11/13 dpb
6/11/13 Wanderson
6/11/13 dpb
6/11/13 Wanderson
6/11/13 dpb
6/12/13 dpb
6/12/13 Wanderson
6/12/13 Wanderson
6/12/13 dpb
6/12/13 Alan Weiss
6/12/13 dpb
6/13/13 Steven Lord
6/15/13 Bruno Luong