plot dirac function in matlab

北城以北 提交于 2020-01-03 03:11:10

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!