在matlab中直观地绘制一个无穷大的值

gwe*_*dfg 4 matlab plot matlab-figure

我正在尝试重现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])
Run Code Online (Sandbox Code Playgroud)

我的代码产生:

我的身材

Wol*_*fie 10

您可以执行此操作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])
Run Code Online (Sandbox Code Playgroud)

您可以在此处查看输出图,但请参阅下面的编辑以获得改进版本.

请注意,当然您应该选择相对于绘图上任何其他数据较大的值.在这个例子中,我选择了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)
Run Code Online (Sandbox Code Playgroud)

plot2