在对数域中绘制负值的误差条 (Matlab)
我有一个向量,称之为 x,其中包含我根据平均值计算得出的非常小的数字。我想绘制 x 的对数变换,例如 y=10*log10(x),以及在查找平均值时计算出的等于 +- 2 个标准差的误差条。
为此,我使用以下代码:
figure
errorbar(lengths, 10*log10(x), ...
10*log10(x-2*std_x), 10*log10(x+2*std_x), 'o')
我的问题是,由于 x 包含如此小的值,x-2*std_x 通常是负数,并且您不能取负数的对数。
所以我想我的问题是,当减去线性域中的标准差得到负数时,如何在对数域中绘制误差线?我不能做 +-
I have a vector, call it x, which contains very small numbers that I calculated from a mean. I'd like to plot the logarithmic transform of x, say y=10*log10(x), along with errorbars equal to +- 2 standard deviations calculated when finding the mean.
To do this, I'm using the following code:
figure
errorbar(lengths, 10*log10(x), ...
10*log10(x-2*std_x), 10*log10(x+2*std_x), 'o')
My problem is that since x contains such small values, x-2*std_x is usually a negative number, and you can't take the log of negative numbers.
So I suppose my question is how can I plot errorbars in the logarithmic domain when subtracting the standard deviation in the linear domain gives me negative numbers? I can't do the +-
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
实际上,您调用
errorbar
是错误的。您应该调用如果
std_x
太小而无法工作,您可以通过从10*log10(x-2)绘制垂直线来编写自己的
到errorbar
版本*std_x)10*log10(x+2*std_x)
Actually you're calling
errorbar
wrong. You should callIf
std_x
is too small for this to work, you can write your own version oferrorbar
by plotting vertical lines from10*log10(x-2*std_x)
to10*log10(x+2*std_x)
在两个错误配置中使用 errorbar,然后将 y 轴更改为对数:
您可能需要使用 ylim 手动调整 y 轴范围
use errorbar in the two error configuration, then change the y-axis to be logarithmic:
you may want to adjust your yaxis range manually using
ylim
您可以用一个较小但可记录的值替换这些值(例如,低 40 dB):
或者只是阈值到某个最小值:
或者类似的东西。
编辑总结评论和进一步的想法:
人们可能应该考虑为什么有误差线。通常,误差线倾向于指示某种置信度/概率的度量(例如,x% 的时间,该值位于指示的界限之间)。在这种情况下,如果对某个量取一些对数,则该量很可能是从非负分布中得出的。在这种情况下,使用非平均值 +/- K * std_deviation 的边界来指示边界可能更正确。
假设具有 cdf F(x) 的单峰分布,“适当”边界(即对于给定概率而言最小)可能是这样的:
F'(x1) = F'(x2), F(x2) - F(x1 )=desired_probability,并且x1<=众数<=x2。
这是对称分布的平均值 +/- K std_deviation,但如上所述,严格的正分布可能需要不同的处理。
You can replace those values with a small value but log-able (say, 40 dB lower):
Or just threshold to some minimum:
Or similar stuff.
EDIT to summarize comments and further thoughts:
One should probably think about why have error bars. Normally error bars tend to indicate some measure of confidence / probability (e.g. x% of the time, the value is between the indicated bounds). In this case, where some logarithm is taken of a quantity, it is likely that the quantity is drawn from a non-negative distribution. In that case, it is probably more correct to use bounds that are not mean +/- K * std_deviation to indicate bounds.
Assuming a unimodal distribution with cdf F(x), the "proper" bounds (i.e. smallest, for a given probability) would probably be such that
F'(x1) = F'(x2), F(x2) - F(x1) = desired_probability, and x1 <= mode <= x2.
This is mean +/- K std_deviation for a symmetric distribution, but as mentioned, a strictly positive distribution probably requires a different treatment.