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.
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!