MATLAB Answers

0

plot a delta function

Asked by HADIMARGO on 18 May 2019
Latest activity Commented on by Sulaymon Eshkabilov on 18 May 2019
hi guys.
i want to plot this simple delta function.
pls plot this with delta function code.
question.jpg

2 Answers

 채택된 답변

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

  2 Comments

thank you sir.
Hi Hadimargo,
You are most welcome. It is a pleasure. Good luck.

Sign in to comment.



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

tnx for answering . but the shape is not correct:
correct shape is :

Sign in to comment.