Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I've got matrix A(n,m) and I want multiply it to vector b(n), so that the result B[n,m]=A[n,m]*b[n]. It is possible to do it by creating a new matrix C=b*ones(1,m) and then use dot multiplication: B=A.*C, but it is waste of memory (size of A is 5000*1000). It is possible to use loops. Maybe there are more elegant way to do it?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
975 views
Welcome To Ask or Share your Answers For Others

1 Answer

Use bsxfun, which is just for that:

B = bsxfun(@times, A, b(:));

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...