Adding loop for a code

1 次查看(过去 30 天)
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 个评论
Walter Roberson
Walter Roberson 2020-9-27
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 2020-9-27
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.

请先登录,再进行评论。

采纳的回答

Vimal Rathod
Vimal Rathod 2020-9-30
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 个评论
Walter Roberson
Walter Roberson 2020-10-2
Now invoke test_sampen
Hatem Akeel
Hatem Akeel 2020-10-5
Thanks appreciate your help. Works great!

请先登录,再进行评论。

更多回答(0 个)

标签

Community Treasure Hunt

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

Start Hunting!

Translated by