乘矩阵向量 [英] Multiply matrix to vector

查看:138
本文介绍了乘矩阵向量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经得到矩阵A(N,M),我想它乘到向量b(N),从而使结果B [N,M] = A [N,M] * B [N]。它可以通过创建一个新的矩阵 C = B *一(1,M)做,然后使用点乘: B = A。 * C ,但它是浪费内存( A 是5000 * 1000的尺寸)。它可以使用循环。也许有更优雅的方式做到这一点?

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?

推荐答案

使用 bsxfun ,这只是为:

Use bsxfun, which is just for that:

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

这篇关于乘矩阵向量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆