bsxfun

bsxfun implementation in matrix multiplication

不想你离开。 提交于 2019-11-26 08:30:30
问题 As always trying to learn more from you, I was hoping I could receive some help with the following code. I need to accomplish the following: 1) I have a vector: x = [1 2 3 4 5 6 7 8 9 10 11 12] 2) and a matrix: A =[11 14 1 5 8 18 10 8 19 13 20 16] I need to be able to multiply each value from x with every value of A , this means: new_matrix = [1* A 2* A 3* A ... 12* A] This will give me this new_matrix of size (12*m x n) assuming A (mxn) . And in this case (12*4x3) How can I do this using

In Matlab, when is it optimal to use bsxfun?

半城伤御伤魂 提交于 2019-11-26 04:32:39
问题 My Question: I\'ve noticed that a lot of good answers to Matlab questions on SO frequently use the function bsxfun . Why? Motivation: In the Matlab documentation for bsxfun , the following example is provided: A = magic(5); A = bsxfun(@minus, A, mean(A)) Of course we could do the same operation using: A = A - (ones(size(A, 1), 1) * mean(A)); And in fact a simple speed test demonstrates the second method is about 20% faster. So why use the first method? I\'m guessing there are some

Comparing BSXFUN and REPMAT

末鹿安然 提交于 2019-11-26 00:59:42
问题 Few questions were asked before on comparisons between bsxfun and repmat for performance. One of them was: Matlab - bsxfun no longer faster than repmat?. This one tried to investigate performance comparisons between repmat and bsxfun , specific to performing subtraction of an input array\'s mean along the columns from the input array itself and as such would explore only the @minus part of bsxfun against its repmat equivalent. Another was : In Matlab, when is it optimal to use bsxfun?. That