Why i get different output?
1 view (last 30 days)
Show older comments
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.
0 Comments
Answers (1)
Star Strider
on 24 Dec 2014
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.
0 Comments
See Also
Categories
Find more on Antennas, Microphones, and Sonar Transducers in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!