Adding loop for a code

5 visualizaciones (últimos 30 días)
Hatem Akeel
Hatem Akeel el 26 de Sept. de 2020
Comentada: Hatem Akeel el 5 de Oct. de 2020
I'm using the code from the link below
I need your help in modifing the code in the above link. I want to modify the code to add a loop for it. For example I have 2000 obervation and I need it to calcualte entropy for the first 120 obervation. Then it will take the next 120 obervation by leaving the first observation (1-lag). The output will be a vector of sample entropy.
  2 comentarios
Walter Roberson
Walter Roberson el 27 de Sept. de 2020
Then it will take the next 120 obervation by leaving the first observation (1-lag)
I am not sure that I understand that ? Is lag fixed? Is lag something you would calculate by using a function such as https://www.mathworks.com/help/signal/ref/finddelay.html ?
Do I understand correctly that the first iteration, you would submit the first 120 observations (total = 120), calculate entropy, then each iteration after that, you would add in an artificial first sample that had value (1-lag) together with the next 120 observations, for a total of 121 observations going into the entropy calculation?
Hatem Akeel
Hatem Akeel el 27 de Sept. de 2020
Thanks for your prompt response !
lets say you have the folllowing observatiion ( 10,20,30,40,... 20,000) which are 2000 obsevations. The first iteration or calcuation will be from 10 until 1200. 2nd iteration or calcuation will be from 20 until 1210. 3rd will be from 30 until 1220 and so on and so forth. I need to make this loop of calcuation in the code.
I hope that will explain it.

Iniciar sesión para comentar.

Respuesta aceptada

Vimal Rathod
Vimal Rathod el 30 de Sept. de 2020
Hi,
For making a bunch of iterations on the observation array you could directly loop through each element and call the "SampEn" function inside the loop and store the values in an array.
n = 2000; % number of observations
l = 120; % length of single set
observations = rand(1,n); % Consider this as observations
entropy = zeros(1,(n-l+1)); % initializing the entropy vector
for i = 1:(n-l+1)
% just included temporary values in the function.
entropy(i) = SampEn(observations(i:i+l-1),1,0.2);
end
Hope this helps.
  13 comentarios
Walter Roberson
Walter Roberson el 2 de Oct. de 2020
Now invoke test_sampen
Hatem Akeel
Hatem Akeel el 5 de Oct. de 2020
Thanks appreciate your help. Works great!

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by