Sum elements of matrix aside from the first row or column

조회 수: 24 (최근 30일)
Manu Mensa
Manu Mensa 2018년 12월 18일
댓글: madhan ravi 2018년 12월 19일
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.

채택된 답변

madhan ravi
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
madhan ravi 2018년 12월 19일
Foul Yusuf‘s answer moved here for consistency:
Thank you very much , Madhan Ravi

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by