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: matrix with column-wise increasing values
Replies: 8   Last Post: Aug 8, 2014 5:47 PM

 Messages: [ Previous | Next ]
 Curious Posts: 2,359 Registered: 12/6/04
Re: matrix with column-wise increasing values
Posted: Aug 7, 2014 3:45 PM

"manu" wrote in message <ls0iqr\$nfr\$1@newscl01ah.mathworks.com>...
> Thank you very much.
>
> Unfortunately, this is approach is a bit too slow.
>
> I need to work with vector multiplication as I have several millions of iterations and the matrix is also a bit bigger.
>
> But thank you very much for your thoughts and your work!!!

I don't have MATLAB installed on this computer, so I can't test this out, but it seems to me you should be able to use bsxfun in some clever way. Look at the last example in:

<<http://www.mathworks.com/help/matlab/ref/bsxfun.html>>

or

doc bsxfun

Perhaps something like this will work for your example:

A = 1:5;
B = (0:3).';
C = bsxfun(@plus,A,B)

Like I said, I can't test the above, but you should get the idea.
Also, even if it works, I don't know if it will be any faster than an efficient for loop version.
It will depend on the size of your array and the memory you have available.

Date Subject Author
8/7/14 manu
8/7/14 William Frane
8/7/14 manu
8/7/14 Curious
8/7/14 wicore
8/7/14 wicore
8/7/14 dpb
8/7/14 manu
8/8/14 Roger Stafford