在matlab中可视化绘制一个无穷大的值
我试图重现狄拉克δ函数: 我的代码:在matlab中可视化绘制一个无穷大的值,matlab,plot,matlab-figure,Matlab,Plot,Matlab Figure,我试图重现狄拉克δ函数: 我的代码: 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]) 我的代码生成: 要显示无穷大,不应将y设置为无穷大。为此,可以将y设置为与轴值成比例的大值。例如,如果轴类似于[min\u
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])
我的代码生成:
要显示无穷大,不应将
y
设置为无穷大。为此,可以将y
设置为与轴值成比例的大值。例如,如果轴类似于[min\u x max\u x min\u y max\u y]
,则可以设置y(x==0)=max\u y*10
在您的情况下,您将拥有:
x = -30:1:30; min_x = min(x) - 10; max_x = max(x) + 10;
y = zeros(1,numel(x));
% compute values of y here
% ...
min_y = min(y) - 10; max_y = max(y) + 10;
y(x==0)= 10 * max_y;
plot(x,y,'d');
axis([min_x max_x min_y max_y]);
您可以使用
stem
,将其“标记”
指定为向上箭头
% 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])
您可以看到,但请参见下面的编辑以了解改进的版本
注意,当然,您应该选择一个y值,该值相对于绘图上的任何其他数据都较大。在本例中,我选择了75以大致匹配所需的示例图。MATLAB无法在inf
处绘制值,因为无穷大在y轴上的位置
编辑:您可以使用附加的
指示y轴断开≈'代码>Marco在评论中建议的字符。将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绘图中使用勾号属性,如下所述
除了显示≈代码>在y轴上可以添加类似于文本(-41.7,75,'≈', 'Fontsize',20)
和文本(41.7,75,'≈', 'Fontsize',20)
并且不显示70以上的yticks。@Marco您只需调用text
就可以做到这一点,就像这样:text([-42,38],[80,80],'≈', 'Fontsize',20)
然后调用yticks
就像这样:yticks(0:20:60)
Heh。美好的狄拉克会感到骄傲的+1.x=[-30,0,0,0,30]
y=[0,0,80,0,0]
绘图(x,y)