howk 发表于 2006-10-14 10:23

求助大虾!

本人写的一段信道差错概率与信道容量的小程序,在编译时出现错误提示:Subscript indices must either be real positive integers or logicals.出错的是H(p)=-sum(p.*log2(p)); 请哪位大虾指点迷津!不甚感激!程序如下:

echo on
gamma_db=[-20:0.1:20];
gamma=10.^(gamma_db./10);
p_error=1/2.*erfc(sqrt(gamma));
%capacity=1.-entropy2(p_error);
p=p_error;
H(p)=-sum(p.*log2(p));
capacity=1.-H(p);
pause % Press a key to see a plot of error probability vs. SNR/bit.
clf
semilogx(gamma,p_error)
xlabel('SNR/bit')
title('Error probability versus SNR/bit')
ylabel('Error Prob.')
pasue % Press a key to see a plot of channel capacity vs. SNR/bit.
clf
semilogx(gamma,capacity)
xlabel('SNR/bit')
title('Channel capacity versus SNR/bit')
ylabel('Channel capacity')


还有就是 entropy2()命令matlab中不认,那不是默认函数吗?帮帮忙 ! 急!
谢谢!

jimin 发表于 2006-10-14 11:29

H(p)=-sum(p.*log2(p));
Subscript indices must either be real positive integers or logicals.
H(p)这里的p应为正整数,可能问题出在这里

howk 发表于 2006-10-14 12:08

thanks
页: [1]
查看完整版本: 求助大虾!