Adding loop for a code

3 views (last 30 days)
Hatem Akeel
Hatem Akeel on 26 Sep 2020
Commented: Hatem Akeel on 5 Oct 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.
Hatem Akeel
Hatem Akeel on 27 Sep 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.

Sign in to comment.

Accepted Answer

Vimal Rathod
Vimal Rathod on 30 Sep 2020
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);
Hope this helps.
Hatem Akeel
Hatem Akeel on 5 Oct 2020
Thanks appreciate your help. Works great!

Sign in to comment.

More Answers (0)


Community Treasure Hunt

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

Start Hunting!