Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个5x5矩阵 M = magic(5) and I must add two sub-matrices of it (using thesum command) and store it inG`,它们是:
5x5
and I must add two sub-matrices of it (using the
command) and store it in
M(1:3,1:3)和M(3:5,3:5)
M(1:3,1:3)
M(3:5,3:5)
我写了这个,但我不确定它是否正确,
G=sum(M([1:3,1:3],[3:5,3:5]));
如评论中所述,您可以使用+.
+
M = magic(5); A = M(1:3,1:3); B = M(3:5,3:5); G = A + B;
如果你想使用它可能会变得有点复杂sum,
sum
C(:,:,1) = A; C(:,:,2) = B; G = sum(C,3);