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