如何在MATLAB中翻转histc函数的edges(1)和edges(end)的定义?
在 MATLAB: 中
n = histc(x,edges);
定义如下:
n(k) 对值 x(i) 进行计数,如果有edges(k) <= x(i) <=边(k+1)。最后一个垃圾箱 计算任何匹配的 x 值 边缘(结束)。
有没有什么方法可以翻转结束行为,使得 n(1) 计算与edges(1)匹配的x的任何值,并且n(end)计算满足edges(end-1) <=的值x(i) x(i) <边缘(结束)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
考虑以下代码:
根据发布的问题,上面将返回:
edges(k-1) <= x(i)
,则对值 x(i) 进行计数Edges(k)
这与 gnovice 解决方案,因为他的答案使用了边界:edges(k-1)
edges(k-1)
edges(k-1)
edges(k-1)
edges(k-1)
edges(k-1) x(i) <= Edges(k)
(注意等号的位置)。为了进行演示,请考虑这个简单的示例:
反对:
Consider the following code:
According to the question posted, the above will return:
edges(1)
edges(k-1) <= x(i) < edges(k)
This different from gnovice solution in that his answer uses the bounds:
edges(k-1) < x(i) <= edges(k)
(note the position of the equality sign).To demonstrate, consider this simple example:
Against:
由于edges参数必须具有单调非递减的值,因此翻转边缘行为的一种方法是否定并翻转edges参数并否定分箱的值。如果您随后翻转 HISTC 的 bin 计数输出,您应该看到 HISTC 的典型边缘行为相反:
上面使用 FLIPLR,因此
x
和edges
应该是行向量(即1×N)。此代码将根据以下条件对数据进行分箱:n(1)
对与edges(1)
匹配的x
值进行计数。n(k)
对值x(i)
进行计数,使得edges(k-1)
edges(k-1)
x(i) <= 边(k)
。请注意,这会翻转所有 bin 的边缘行为,而不仅仅是第一个和最后一个 bin! bin
典型行为>n(k)
使用方程edges(k) <= x(i)
edges(k) <= x(i)
Edges(k+1)
(注意索引之间的差异以及哪一侧有等号!)。编辑:经过一番讨论...
如果您相反想根据以下标准对数据进行分箱:
n(1)
计数与edges(1)
匹配的任何x
值。n(2)
对值x(i)
进行计数,使得edges(1)
x(i) <边缘(2)
。n(k)
对值x(i)
进行计数,使得edges(k-1) <= x(i) <边(k)。
然后,以下内容应该完成此操作:
第一个 bin 应仅捕获等于
edges(1)
的值,而第二个 bin 的下边缘应从高于edges(1) 的增量值开始
(使用 EPS 函数找到)。最后一个 bin,它计算等于edges(end)
的值的数量,被丢弃。Since the
edges
argument has to have monotonically nondecreasing values, one way to flip the edge behavior is to negate and flip theedges
argument and negate the values for binning. If you then flip the bin count output from HISTC, you should see the typical edge behavior of HISTC reversed:The above uses FLIPLR, so
x
andedges
should be row vectors (i.e. 1-by-N). This code will bin data according to the following criteria:n(1)
counts any values ofx
that matchedges(1)
.n(k)
count the valuesx(i)
such thatedges(k-1) < x(i) <= edges(k)
.Note that this flips the edge behavior of all the bins, not just the first and last bins! The typical behavior of HISTC for bin
n(k)
uses the equationedges(k) <= x(i) < edges(k+1)
(Note the difference between the indices and which side has the equals sign!).EDIT: After some discussion...
If you instead wanted to bin data according to the following criteria:
n(1)
counts any values ofx
that matchedges(1)
.n(2)
counts the valuesx(i)
such thatedges(1) < x(i) < edges(2)
.n(k)
count the valuesx(i)
such thatedges(k-1) <= x(i) < edges(k)
.Then the following should accomplish this:
The first bin should capture only values equal to
edges(1)
, while the lower edge of the second bin should start at an incremental value aboveedges(1)
(found using the EPS function). The last bin, which counts the number of values equal toedges(end)
, is thrown out.