how can i do that for all columns?

hi , i have a matrix (length(a),length(b)) and i want to write a function that calculates the sum of all a in a column. how can i do that for all columns?

답변 (1개)

Suraj Mankulangara
Suraj Mankulangara 2018년 3월 13일

0 개 추천

Hi Ach
The "sum" function in MATLAB returns the total of all elements in a column (or row) of a matrix. For more information on how to use the sum function, you can refer to the link below:
https://in.mathworks.com/help/matlab/ref/sum.html
By default, the "sum" function computes column-wise total of elements in a matrix, so in your case,
sum(matrix)
should get you the result that you want.

댓글 수: 1

Stephen23
Stephen23 2018년 3월 13일
편집: Stephen23 2018년 3월 13일
although to be safe, in case the size of the matrix might change in future:
sum(matrix,1)

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

질문:

Ach
2018년 3월 5일

편집:

2018년 3월 13일

Community Treasure Hunt

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

Start Hunting!

Translated by