本人写的一段信道差错概率与信道容量的小程序,在编译时出现错误提示: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')