I have an array of 2000x1 = D .
i have a condition D>25. for D>25 higher than 20 sec i should count 1 event.
how can i do this in matlab?

 Respuesta aceptada

Thorsten
Thorsten el 5 de Nov. de 2015
Editada: Thorsten el 5 de Nov. de 2015

0 votos

If D contains an entry every second, you can use:
D = randi(2000, 1, 20); % sample data
di = diff([0 D > 25 0]);
i1 = find(di == 1);
i2 = find(di == -1);
Nevents = nnz(i2 - i1 > 20);

3 comentarios

Heartrin
Heartrin el 5 de Nov. de 2015
Dimensions of matrices being concatenated are not
consistent.
Error in t (line 10)
di = diff([0 D > 25 0]);
this is the error if i use the above code
Thorsten
Thorsten el 5 de Nov. de 2015
What's the size of D? If it is 20000x1 as you said in your original post, then it should work. If it is 1x20000, you have to use
di = diff([0; D > 25; 0]);
Heartrin
Heartrin el 5 de Nov. de 2015
Thanks . you are awesome.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Get Started with MATLAB en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 5 de Nov. de 2015

Comentada:

el 5 de Nov. de 2015

Community Treasure Hunt

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

Start Hunting!

Translated by