## plot a delta function

on 18 May 2019
Latest activity Commented on by Sulaymon Eshkabilov

on 18 May 2019

### Sulaymon Eshkabilov (view profile)

hi guys.
i want to plot this simple delta function.
pls plot this with delta function code. Walter Roberson

18 May 2019

### Tags

Sulaymon Eshkabilov

### Sulaymon Eshkabilov (view profile)

님의 답변 18 May 2019
채택된 답변

use stem() instead of plot() and you'll get it as shown in your image.
n=-10:10; % E.g. use any space
N1 = 2; % E.g. set up at any value
x = zeros(size(n));
for jj=1:numel(n)
if abs(n(jj))<=N1
x(jj)=1;
else
x(jj)=0;
end
end
stem(n, x)
title('\delta function'), shg

18 May 2019
thank you sir.
Sulaymon Eshkabilov

### Sulaymon Eshkabilov (view profile)

18 May 2019
You are most welcome. It is a pleasure. Good luck.

Sulaymon Eshkabilov

### Sulaymon Eshkabilov (view profile)

님의 답변 18 May 2019

Hi,
here is one of the possible solutions:
n=-10:10; % E.g. use any space
N1 = 2; % E.g. set up at any value
x = zeros(size(n));
for jj=1:numel(n)
if abs(n(jj))<=N1
x(jj)=1;
else
x(jj)=0;
end
end
plot(n, x, 'k-', 'linewidth', 2), grid on
title('\delta function'), shg
Good luck.

#### 1 Comment 