yuan2005 发表于 2007-5-7 20:34

近似熵

我是一个新手 我这有个程序函数不知道怎么定义请大家帮帮忙
function = fast_ApEn(signal,r_factor)
signal=signal(:);
N=length(signal);
Cmr_ij=[];Cmr_i=[];Cmr=[];
Cmr_ij_1=[];Cmr_i_1=[];Cmr_1=[];
D=abs(signal*ones(1,N)-ones(N,1)*signal');
S=zeros(N,N);
S(find(D<=r_factor*std(signal)))=1;
m=2;
S(N+1,(m+1):N)=0;
for k=1:N-(m-1)
Cmr_ij=S(k,1:N-1).*S(k+1,2:N);
Nm_i=sum(Cmr_ij);
Cmr_i=Nm_i/(N-(m-1));
Cmr=;Cmr_ij(end)=[];
Cmr_ij_1=Cmr_ij.*S(k+2,3:N);
Nm_i_1=sum(Cmr_ij_1);
Cmr_i_1=Nm_i_1/(N-m);
Cmr_1=;
end
Cmr_1(end)=[];
phi_m=mean(log(Cmr));
phi_m_1=mean(log(Cmr_1));
ApEn_value=;
运行错误:
??? Input argument 'signal' is undefined.
Error in ==> C:\Documents and Settings\dc.DC-YUAN\桌面\毕业设计文档\数据源与程序\小波包与近似熵\fast_ApEn.m
On line 40==> signal=signal(:);

eight 发表于 2007-5-7 23:47

原帖由 yuan2005 于 2007-5-7 20:34 发表 http://forum.vibunion.com/forum/images/common/back.gif
我是一个新手 我这有个程序函数不知道怎么定义请大家帮帮忙
function = fast_ApEn(signal,r_factor)
signal=signal(:);
N=length(signal);
Cmr_ij=[];Cmr_i=[];Cmr=[];
Cmr_ij_1=[ ...

建议好好看看置顶贴:聚宝盆,你要的答案里面就有

yuan2005 发表于 2007-5-8 20:15

没看见答案啊

答案在哪?我没找到麻烦告诉我一下

eight 发表于 2007-5-8 20:21

原帖由 yuan2005 于 2007-5-8 20:15 发表 http://forum.vibunion.com/forum/images/common/back.gif
答案在哪?我没找到麻烦告诉我一下


8. 对于初学者,建议先阅读以下链接的精华帖:[原创]写给学习 matlab 的新手们

打开那个帖子,然后看第6个技巧

yuan2005 发表于 2007-5-8 21:02

这么输入对吗?

>> a=6000
a =
      6000
>> b=2
b =
   2
>> c=0.35
c =
    0.3500
>> z=ApEn(a,b,c)
这么输入对吗?怎么出现这样的结果呢
Warning: Divide by zero.
(Type "warning off MATLAB:divideByZero" to suppress this warning.)
> In E:\matlab\toolbox\matlab\datafun\mean.m at line 26
In E:\cc\data\小波包与近似熵\ApEn.m at line 30
Warning: Divide by zero.
(Type "warning off MATLAB:divideByZero" to suppress this warning.)
> In E:\matlab\toolbox\matlab\datafun\mean.m at line 26
In E:\cc\data\小波包与近似熵\ApEn.m at line 31
z =
   NaN

[ 本帖最后由 eight 于 2007-5-9 16:52 编辑 ]

yuan2005 发表于 2007-5-8 21:28

matlab

我是一个新手 我这有个错误不知道怎么改请大家帮帮忙
function = fast_ApEn(signal,r_factor)
signal=6000;
m=2;
r_factor=0.35;
signal=signal(:);
N=length(signal);
Cmr_ij=[];Cmr_i=[];Cmr=[];
Cmr_ij_1=[];Cmr_i_1=[];Cmr_1=[];
D=abs(signal*ones(1,N)-ones(N,1)*signal');
S=zeros(N,N);
S(find(D<=r_factor*std(signal)))=1;
m=2;
S(N+1,(m+1):N)=0;
for k=1:N-(m-1)
Cmr_ij=S(k,1:N-1).*S(k+1,2:N);
Nm_i=sum(Cmr_ij);
Cmr_i=Nm_i/(N-(m-1));
Cmr=;Cmr_ij(end)=[];
Cmr_ij_1=Cmr_ij.*S(k+2,3:N);
Nm_i_1=sum(Cmr_ij_1);
Cmr_i_1=Nm_i_1/(N-m);
Cmr_1=;
end
Cmr_1(end)=[];
phi_m=mean(log(Cmr));
phi_m_1=mean(log(Cmr_1));
ApEn_value=;
运行错误:
??? Subscript indices must either be real positive integers or logicals.
Error in ==> E:\cc\data\小波包与近似熵\fast_ApEn.m
On line 66==> Cmr_1(end)=[]; % the last C value for the "m+1" pattern is artificial.

eight 发表于 2007-5-8 21:38

原帖由 yuan2005 于 2007-5-8 21:02 发表 http://forum.vibunion.com/forum/images/common/back.gif
>> a=6000
a =
      6000
>> b=2
b =
   2
>> c=0.35
c =
    0.3500
>> z=ApEn(a,b,c)
这么输入对吗?怎么出现这样的反映呢
Warning: Divide by zero.
(Type "warning off MATLAB:divideByZer ...

这是另外一个问题了。自己好好调试一下你的代码吧

ps:你上面那个帖子的调用的命令是 ApEn ,可是你一楼的帖子中,函数名是 fast_ApEn,注意需保持文件名和函数名一致

yuan2005 发表于 2007-5-8 22:15

这个错误在我的ApEn函数里面也出现这样的错误, 我不知道是那里出错了 能指点一下吗?

yuan2005 发表于 2007-5-9 16:50

function = ApEn(signal,m,r_factor)
signal=6000;
m=2;
r_factor=0.35;
signal=signal(:)';
N=length(signal);
= C_m_computation(signal,m,r_factor);
= C_m_computation(signal,m+1,r_factor);
phi_m=mean(log(C_m));
phi_m_1=mean(log(C_m_1));
ApEn_value=;

% -------------------------------------------------------------------
function = C_m_computation(signal,m,r_factor)
X=[];C_im=[];n_im=[];max_dif=[];
N=length(signal);

for j=1:N-m+1
X(j,:)=signal(j:j+m-1);
end

for j=1:N-m+1
aux1=repmat(X(j,:),N-m+1,1);
dif_aux=abs(X-aux1);
n_im=0;
for k=1:N-m+1
if max(abs(dif_aux(k,:)))<r_factor*std(signal)
n_im=n_im+1;
end
end
C_im=;
end
结果:
>> Warning: Divide by zero.
(Type "warning off MATLAB:divideByZero" to suppress this warning.)
> In E:\matlab\toolbox\matlab\datafun\mean.m at line 26
In E:\cc\data\小波包与近似熵\ApEn.m at line 32
Warning: Divide by zero.
(Type "warning off MATLAB:divideByZero" to suppress this warning.)
> In E:\matlab\toolbox\matlab\datafun\mean.m at line 26
In E:\cc\data\小波包与近似熵\ApEn.m at line 33

ans =

   NaN
页: [1]
查看完整版本: 近似熵