Curious
Posts:
2,311
Registered:
12/6/04


Re: matrix with columnwise 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.

