MATLAB 不同维度矩阵加减乘除

>> A=[1,2,3;4,5,6;7,8,9],B=[1,2;3,4]

A =

1 2 3

4 5 6

7 8 9

 

B =

1 2

3 4

 

>> [rA,cA]=size(A); %得到A大小

>> [rB,cB]=size(B);

>> C=zeros(max(rA,rB),max(cA,cB));%得到A和B最大的行列

>> C(1:rA,1:cA)=A;%把C填充为A

%在下面进行加减乘除

>> C(1:rB,1:cB)=C(1:rB,1:cB)+B;%再去相加对应的B行列

>> C

C =

2 4 3

7 9 6

7 8 9

 

上一篇:HCIE笔记-第七节-ICMP+ARP


下一篇:Effective C++ Item 9 Never call virtual functions during constrution or destruction