MATLAB爱好者论坛-LabFans.com

MATLAB爱好者论坛-LabFans.com (https://www.labfans.com/bbs/index.php)
-   MATLAB论坛 (https://www.labfans.com/bbs/forumdisplay.php?f=6)
-   -   [MATLAB基础] matlab矩阵相乘的问题 (https://www.labfans.com/bbs/showthread.php?t=7923)

tianya6421 2009-04-26 10:29

matlab矩阵相乘的问题
 
A=[1 2 3 4];
B=[1 2;2 3;3 4;4 5]
让AB中行相乘
要达到A中的1 分别乘以B中的 1 2
A中的2分别乘以B中的 2 3
A中的3分别乘以B中的 3 4
A中的4分别乘以B中的 4 5
直接A.*B肯定不行

求大侠指点一下,怎么解决这个问题

fml 2009-04-26 10:59

回复: matlab矩阵相乘的问题
 
看以用这样一个循环试试:
A=[1 2 3 4]; B=[1 2; 2 3; 3 4;4 5];
for i=1:4
for j=1:2
AB(i,j)=A(i)*B(i,j);
end
end
AB

麒麟子 2009-04-28 23:19

回复: matlab矩阵相乘的问题
 
楼上的写的不错,用循环比较好

TTT_IOU 2009-04-30 09:43

回复: matlab矩阵相乘的问题
 
下程序可否:
A=[1 2 3 4];
B=[1 2;2 3;3 4;4 5];
for i=1:4
C(i,: )=A(i).*B(i,: );
end
希望有帮助!!

laosam280 2009-04-30 09:57

回复: matlab矩阵相乘的问题
 
there is a more easier way to reach. you can change the dimensions of matrix A by using A,and than do a point time.
codes as follow are tested ok:
A=[1 2 3 4];
A1=[A;A]';
B=[1 2;2 3;3 4;4 5];
ans=A1.*B
>>
ans =

1 2
4 6
9 12
16 20


所有时间均为北京时间。现在的时间是 04:26

Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.