Add multiple rows of a matrix in one row.

9 次查看(过去 30 天)
I have a matrix with 'n' rows and 3 columns. I want to add all the rows and at the end generate a 1x3 matrix. I want all the elements of the 1st column to add up, 2nd column elements to add with eachother and, and the elements of the 3rd column to add up.
Kindly guide me regarding this. Thank You.

采纳的回答

the cyclist
the cyclist 2023-9-26
编辑:the cyclist 2023-9-26
% Create an input matrix like yours
n = 4;
M = rand(n,3)
M = 4×3
0.3111 0.6975 0.6934 0.1395 0.5117 0.1144 0.9389 0.6369 0.9691 0.6248 0.8460 0.8940
% Calculate the sum
sumM = sum(M)
sumM = 1×3
2.0143 2.6921 2.6709
As you may realize, this is a very basic MATLAB question. You would likely benefit from the free online MATLAB Onramp tutorial.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by