apen.m

来自「matlab下实现kaplan算法」· M 代码 · 共 46 行

M
46
字号
function entropy = apen(pre, post, r)% computer approximate entropy a la Steve Pincus[N,p] = size(pre);% how many pairs of points are closer than r in the pre spacephiM = 0;% how many are closer in the post valuesphiMplus1 = 0; % will be used in distance calculationfoo = zeros(N,p);% Loop over all the pointsfor k=1:N   % fill in matrix foo to contain many replications of the point in question   for j=1:p	foo(:,j) = pre(k,j);   end   % calculate the distance    goo = (abs( foo - pre ) <= r );   % which ones of them are closer than r using the max norm   if p == 1      closerpre = goo;   else      closerpre = all(goo');   end   precount = sum(closerpre);   phiM = phiM + log(precount);   % of the ones that were closer in the pre space, how many are closer   % in post also   inds = find(closerpre);   postcount = sum( abs( post(closerpre) - post(k) ) < r );    phiMplus1 = phiMplus1 + log(postcount);endentropy = (phiM - phiMplus1)/N;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?