Mazzy
Mazzy

Reputation: 14189

plot dirac function in matlab

I'm trying to plot the Dirac delta function in Matlab using plot, but I don't see anything in the graph. How do I visualize it?

Upvotes: 1

Views: 35553

Answers (2)

Karan Gill
Karan Gill

Reputation: 158

I personally prefer using dirac and setting Inf to 1 or another amplitude.

x = -1:0.1:1;
y = dirac(x);
idx = y == Inf; % find Inf
y(idx) = 1;     % set Inf to some amplitude
stem(x,y)

Of course, the other answer is perfectly valid. This is just personal preference for being explicit.

Upvotes: 1

Serg
Serg

Reputation: 14108

x = -10 : 0.1 : 10;
y = double(x == 0);
plot(x, y);

or

stem(x, y);

Upvotes: 4

Related Questions