how can i count number of zeroes in a martix(containing elements 0s and 1s only) which is below any 1s(means in a column top to bottom , if 0 comes then dont count if 1 comes then count whole 0s below that 1.

조회 수: 1 (최근 30일)
A(:,:,1) =
5 7 8
0 1 9
4 3 6
A(:,:,2) =
1 0 4
3 5 6
9 8 7
  댓글 수: 2
Stephen23
Stephen23 2017년 10월 25일
What does A have to do with your question? A is not a matrix, and it does not contain only ones and zeros, so it is unclear how it relates to your question.
ntsh kr
ntsh kr 2017년 10월 29일
yes i did a mistake in asking , soory there must be only 0 and 1 but i didnot and in my problem A is a 3d array. thanks

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

채택된 답변

Stephen23
Stephen23 2017년 10월 25일
편집: Stephen23 2017년 10월 25일
>> M = randi(0:1,5,6)
M =
0 1 1 1 0 1
0 1 0 0 0 1
1 0 0 0 1 0
1 1 1 0 0 1
0 0 0 1 1 1
>> sum(cumsum(M,1) & M==0, 1)
ans =
1 2 3 3 1 1
  댓글 수: 6
ntsh kr
ntsh kr 2017년 11월 7일
thank you sir can we learn theory and logic behind sum(cumsum(... &...) command plaese share the link
Stephen23
Stephen23 2017년 11월 7일
@ntsh kr: read the MATLAB documentation. It is easy to search using any internet search engine. This was the first result returned when I searched for "MATLAB cumsum":

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by