Number of non-zero element

조회 수: 3 (최근 30일)
Hg
Hg 2016년 3월 16일
댓글: Hg 2016년 3월 16일
I have n-number of arrays, I want to find the total non-zero element at a location. For example there are three arrays as following:
A = [2 0 0 2;
0 1 1 1;
1 3 0 0;
0 1 0 1];
B = [0 2 1 0;
3 1 1 1;
2 0 0 2;
0 1 0 1];
C = [0 2 3 0;
3 1 2 2;
4 0 2 1;
2 0 0 1]
How can I find the total number of non-zero elements in A, B, C for each location, e.g (1,1): 1, (1,2): 2, (1,3): 2 ? To get array D = [1 2 2 1; 2 3 3 3; ... ].

채택된 답변

James Tursa
James Tursa 2016년 3월 16일
편집: James Tursa 2016년 3월 16일
D = sum(cat(3,A,B,C)~=0,3);
  댓글 수: 1
Hg
Hg 2016년 3월 16일
Never thought about that! Thanks!

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

추가 답변 (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