Why i get different output?

1 次查看(过去 30 天)
aerun martin
aerun martin 2014-12-24
回答: Star Strider 2014-12-24
n=-10:10;
g1=-2*(n<=-5);
g2=n.*(n==-4);
g3=n.*(n==-3);
g4=n.*(n==-2);
g5=n.*(n==-1);
g6=n.*(n==0);
g7=(4./n).*(n>=1);
G=g1+g2+g3+g4+g5+g6+g7;
subplot(3,2,1);
stem(n,G,'r','filled','linewidth',1)
xlabel('n');
ylabel('G[n]');
title ('G[n] against n');
this is my code. i suppose to get as below.

回答(1 个)

Star Strider
Star Strider 2014-12-24
There may be better solutions, but the easiest way I can think of the avoid the NaN at 0 is simply to add eps to ‘n’ in the denominator of ‘g7’:
g7=(4./(n+eps)).*(n>=1);
since that is generating it.

类别

Help CenterFile Exchange 中查找有关 Antennas, Microphones, and Sonar Transducers 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by