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

标签 matlab plot matlab-figure

我正在尝试重现 Dirac Delta 函数:

Dirac Delta Function

我的代码:

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])

我的代码产生:

My figure

最佳答案

您可以使用 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 轴被打断。将 xlimylim 组合到一个 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)

plot2

关于matlab - 在matlab中直观地绘制一个无穷大的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48902508/

相关文章:

c++ - 在 COM 服务器函数中为 int 参数传递 bool 值

matlab - 在 MATLAB 中获取 0 数组中随机 1 的位置

python-2.7 - 如何在 google colab 中运行 matlab .m 文件

matlab - 如何在 Matlab 中减小直方图上条形的宽度

matlab - 如何将matlab矢量转换为3D矩阵

r - Matlab 的 fminunc 函数的 R 等价物是什么?

matlab - 如何在Matlab中使纵坐标的负侧指向上方?

r - 在ggplot中绘制置信区间

python - 使用 LinkedBrush gridplot 在 Bokeh 中绘制多个系列

matlab - 仅在 Matlab 图形中更改刻度线颜色