Sum elements of matrix aside from the first row or column
조회 수: 24 (최근 30일)
이전 댓글 표시
I have a matrix
A=rand(10,40401);
How can i sum the elements of the matrix excluding
1.the first row only
2. the first column only.
Thanks.
댓글 수: 0
채택된 답변
madhan ravi
2018년 12월 18일
편집: madhan ravi
2018년 12월 18일
A=rand(3,2) % a short example for you to understand
a=A(2:end,:) % excludes first row
b=A(:,2:end) % excludes first column
a1=sum(a,1) % sum across rows
%or
a2=sum(a,2) % sum across columns
%same for b
Gives:
A =
0.4037 0.2671
0.1224 0.2462
0.3660 0.3607
a =
0.1224 0.2462
0.3660 0.3607
b =
0.2671
0.2462
0.3607
a1 =
0.4884 0.6069
a2 =
0.3686
0.7268
댓글 수: 2
madhan ravi
2018년 12월 19일
Foul Yusuf‘s answer moved here for consistency:
Thank you very much , Madhan Ravi
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!