0

嗨,可以说我的矩阵大小为 5x5。

B=[1 2 3 4 5; 10 20 30 40 50; 100 200 300  400 500; 1000 2000 3000 4000 5000; 10000 20000 30000 40000 50000];

我如何使用函数 sum,对 2 到 4 之间的行求和并得到结果:

A = [1110;2220;3330;4440]
4

2 回答 2

4

You'll find some useful information about matrix indexing in the documentation at http://www.mathworks.co.uk/help/matlab/math/matrix-indexing.html

To illustrate your example, you can use B(2:4,:) to retreive the following:

ans =
          10          20          30          40          50
          100         200         300         400         500
          1000        2000        3000        4000        5000

You can then use the sum function as follows to achieve your desired result:

A = sum(B(2:4,:))

I hope this helps!

All the best,

Matt

于 2013-03-07T18:25:04.493 回答
1
MATLAB>> sum(B(2:4,1:4))

ans =

        1110        2220        3330        4440

如果要转置结果,'请在末尾添加。

于 2013-03-07T18:22:36.867 回答