Hello,
I have accelerometry data in the x, y and z-plane. Now I'm writing code and always doing the same thing 3 times... I want to put this in a forloop. How do I achieve this?
In this code, I'm trying to detect the number of peaks in the data that is higher than a given threshold 1.25. As you can see, I'm doing this 3 times, for the x, y and z-plane. I can't seem to figure out how to put this in a forloop. Can anyone help?
Thank you.
[pks_x_sit1,locs_x_sit1] = findpeaks(x_sit1,'MinPeakHeight',1.25);
nr_pks_x_sit1 = length(pks_x_sit1);
[pks_y_sit1,locs_y_sit1] = findpeaks(y_sit1,'MinPeakHeight',1.25);
nr_pks_y_sit1 = length(pks_y_sit1);
[pks_z_sit1,locs_z_sit1] = findpeaks(z_sit1,'MinPeakHeight',1.25);
nr_pks_z_sit1 = length(pks_z_sit1);

 Respuesta aceptada

KSSV
KSSV el 24 de Mzo. de 2020

0 votos

Let A be your data of size m*3.
for i = 1:3
[pks_x_sit1,locs_x_sit1] = findpeaks(A(:,i),'MinPeakHeight',1.25);
nr_pks_x_sit1 = length(pks_x_sit1);
end

3 comentarios

Sam
Sam el 24 de Mzo. de 2020
Thank you! And how do I use sprintf command to store nr_pks_x_sit1, nr_pks_y_sit1 and nr_pks_z_sit1 seperately using a forloop?
KSSV
KSSV el 24 de Mzo. de 2020
store what and why?
Sam
Sam el 24 de Mzo. de 2020
i've got it. thank you

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

Sam
el 24 de Mzo. de 2020

Comentada:

Sam
el 24 de Mzo. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by