【发布时间】:2014-03-30 22:02:51
【问题描述】:
我有两个问题。 如何将不同维度的数组相乘?
Question 1 Example:
A1=1,2,3,4,5,6
A2=1,2,3
The answer I would like to get would be
A1*A2 =1,4,9,4,10,18
我想只使用 repmat,但这是最好的方法吗?
还有
Question 2 Example:
A1=1,2,3,4,5,6,7 (notice the addition of another value the number 7)
A2=1,2,3
The answer I would like to get would be
A1*A2 =1,4,9,4,10,18,7 (notice the addition of another value the number 7)
我在考虑 for 循环,但数组非常大,有 500,000+ 个值,需要很长时间才能完成。
有没有办法编写一些适用于两个问题/示例的 matlab/代码?
【问题讨论】:
-
1,4,9...?我不确定你是如何获得 1,4,6...
-
你在做元素乘法(
A1.*A2)吗?您的代码显示矩阵乘法 (A1*A2)... -
@Mad Physicist 感谢我将 6 更改为 9 并更新了问题
-
@kkuilla 我不确定我应该使用哪一个,这就是为什么我将示例与我试图获得的答案一起提供
-
我认为您正在寻找逐元素乘法 (
A1.*A2)。
标签: arrays matlab multidimensional-array octave