Multiplying each point in the matrix by one of the other matrices and forming a new matrix from each multiplication, in matlab

Sorry if the question is confusing, but I will explain here. What I want to do is: Suppose we have a vector (or 1xN matrix) A = [a1 a2 a3 a4], and another B = [b1 b2 b3] I want C to be:

[a1*b1 a1*b2 a1*b3 a2*b1 a2*b2 a3*b3 a3*b1 a3*b2 a3*b3 a4*b1 a4*b2 a4*b3] 

Is there a team that will do this in Matlab? I have already done this in a for loop, but given the number of times the loop is called, it will save a lot of execution time if I can write it without a for loop.

+4
source share
1 answer

Yes. This is done with regular vector multiplication and is called an external product . All you have to do is multiply the column vector with the row vector, in this case A.' * B A.' * B Note that A transposed to make it a column vector (your row vector by definition).

+3
source

Source: https://habr.com/ru/post/1388197/


All Articles