我正在尝试重现 Dirac Delta 函数:
我的代码:
x = -30:1:30;
y = zeros(1,numel(x)); %sets all values initially to zero
y(x==0)= inf; % the point corresponding to x=0 is set to inf
plot(x,y,'d')
axis([-40 40 0 inf])
我的代码产生:
最佳答案
您可以使用 stem
执行此操作,将其 'Marker'
指定为向上箭头...
% Open figure
figure;
% Blue stem plot at x=0, to y=75. Marker style is up arrow
stem(0, 75,'color','b','linewidth',2,'marker','^')
% Add infinity label at x=0, y = 82 = 75 + fontsize/2, where we plotted up to 75
text(0,82,'∞','FontSize',14)
% Set axes limits
xlim([-40,40])
ylim([0,90])
你可以看到 output plot here ,但请参阅下面的编辑以获得改进版本。
请注意,您当然应该选择一个相对于图中任何其他数据都较大的 y 值。在这个例子中,我选择了 75 来大致匹配您想要的示例图。 MATLAB 无法在 inf
处绘制值,因为无穷大位于 y 轴的什么位置?
编辑:您可以按照 Marco 在评论中的建议,使用额外的 '≈'
字符来指示 y 轴被打断。将 xlim
和 ylim
组合到一个 axis
调用中,并更改 y 轴刻度以帮助指示轴中断,我们得到以下结果:
stem(0, 80,'color','b','linewidth',2,'marker','^')
text([-42,0,38], [80,87,80], {'≈','∞','≈'}, 'Fontsize', 14)
axis([-40, 40, 0, 100])
yticks(0:20:60)
关于matlab - 在matlab中直观地绘制一个无穷大的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48902508/