用bsxfun将一个矩阵的所有列乘以另一个矩阵 [英] Multiply all columns of one matrix by another matrix with bsxfun

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

问题描述

我有两个矩阵AB,大小均为4x4.将A的第一列与B的所有其他列乘以

I have two matrices A and B, both of size 4x4. multiply the first column of A with all the other columns of B with:

bsxfun(@times, A(:,1),B)

,但我想对A的每一列重复此操作,即A的所有列乘以B的所有列.如何使用bsxfun(没有循环或repmat)来做到这一点?

but what I want to do is to repeat this operation for each column of A, i.e multiply all columns of A by all columns of B. How can I do this with bsxfun (without loops or repmat)?

推荐答案

是,通过

Yes, by permuting the dimensions of one of the matrices to make it a 4x1x4 array:

permute(bsxfun(@times, A, permute(B, [1 3 2])), [1 3 2])

这篇关于用bsxfun将一个矩阵的所有列乘以另一个矩阵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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