Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

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

1 visualización (últimos 30 días)
Tyron Louw
Tyron Louw el 24 de Jul. de 2018
Cerrada: MATLAB Answer Bot el 20 de Ag. de 2021
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!

Respuestas (1)

Paolo
Paolo el 24 de Jul. de 2018
nnz(diff([0 (x==1)])==1)

La pregunta está cerrada.

Etiquetas

Productos


Versión

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by