问题
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?
回答1:
x = -10 : 0.1 : 10;
y = double(x == 0);
plot(x, y);
or
stem(x, y);
回答2:
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.
来源:https://stackoverflow.com/questions/10045081/plot-dirac-function-in-matlab