How to add an NxN matrix with K pages ?

조회 수: 2 (최근 30일)
Syam MS
Syam MS 2020년 7월 24일
편집: James Tursa 2020년 7월 24일
I have an NxN matrix with K pages where each element is a complex number. I need to add the corresponding elements in this K pages. How to do it?
For eg., if A is a 6 X 6 matrix with 4 pages, then I need to obtain solution for A(:,:,1) + A(:,:,2)+A(:,:,3) + A(:,:,4). Alternatively, I felt if using sum(), sum(A,4) should give my required answer. But sum(A,3) is giving the required answer. So, which command should be used to find the sum of elements in an NxN matrix having K pages?

답변 (1개)

James Tursa
James Tursa 2020년 7월 24일
You are correct, sum(A,3) is the correct syntax to use. This sums across the 3rd dimension.
  댓글 수: 4
Syam MS
Syam MS 2020년 7월 24일
That means if A is NxNxK array, always sum(A,3) need to be used. Thanks.
James Tursa
James Tursa 2020년 7월 24일
편집: James Tursa 2020년 7월 24일
Yes. The sum(A,3) syntax works for any array sized NxNxK, and will sum all of the K pages since K is the 3rd dimension.

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

카테고리

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