Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

How do I count the number of new occurrences of a number in an array?

조회 수: 1 (최근 30일)
Tyron Louw
Tyron Louw 2018년 7월 24일
마감: MATLAB Answer Bot 2021년 8월 20일
I have an array given as
x = [1 1 1 1 1 1 1 2 2 1 1 1 3 3 3 3 1 1 1 1 3 1 5]
I am trying to calculate how many new occurrences there are of the number 1. Importantly, this should ignore whether or how many times 1 recurs in the adjacent cell. In the above example, the answer would be 4, because there are 4 instances of 1 appearing, even though they differ in length.
Thanks!

답변 (1개)

Paolo
Paolo 2018년 7월 24일
nnz(diff([0 (x==1)])==1)

태그

제품


릴리스

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by