不同维度矩阵的元素明智乘法 [英] Element wise multiplication of matrices of differing dimensions

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

问题描述

在Matlab中,我需要将元素的两个矩阵乘以M x N和M x kN维.换句话说,它们的高度相同,但是第二个矩阵的宽度是k倍,因此矩阵A中的每个元素必须乘以矩阵B中该行的k个元素.

In Matlab, I need to multiply element wise two matrices of M x N and M x kN dimensions. In other words they are of the same height, but the second matrix is k times wider, so each element in matrix A must be multiplied by k elements of the row in matrix B.

解释起来有些棘手,如果不清楚,我们感到抱歉.显然我知道.*,但是我不知道如何使它工作.

It's a bit tricky to explain, I'm sorry if it's not clear. Obviously I'm aware of .* but I can't figure out how to get this working.

A = [2 3;...
    4 5]
B = [9 8 7 6;...
    8 7 6 5]

我需要乘以| 2 * 9、2 * 8、3 * 7、3 * 6 | 4 * 8、4 * 7、5 * 6、5 * 5 |得到结果

I need to multiply |2*9, 2*8, 3*7, 3*6| 4*8, 4*7, 5*6, 5*5| to get the result

C = [18 16 21 18;...
    32 28 30 25]

能否在不使用繁琐的for循环的情况下有效地做到这一点?谢谢大家!

Can this be done efficiently without resorting to a cumbersome for loop? Thanks guys!

推荐答案

您可以执行类似的操作,这似乎是您想要的,并且提供与您发布的结果相同的结果.

You could do something like this, Which seems to be what you want and provides the same results as what you post.

A = [2 3;
     4 5];
B = [9 8 7 6;
     8 7 6 5];
A = imresize(A,size(B),'nearest');
C = A.*B

这仅在您要介绍的特定情况下才有效.它还假定您具有图像处理工具箱

This will only really work in the particular case you are presenting though. It also assumes you have the image processing toolbox

这篇关于不同维度矩阵的元素明智乘法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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