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.
댓글 수: 0
채택된 답변
the cyclist
2023년 9월 26일
편집: the cyclist
2023년 9월 26일
% Create an input matrix like yours
n = 4;
M = rand(n,3)
% Calculate the sum
sumM = sum(M)
As you may realize, this is a very basic MATLAB question. You would likely benefit from the free online MATLAB Onramp tutorial.
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!