登录论坛

查看完整版本 : 我是否使用histc是错误的,还是这是MATLAB的错误?


poster
2019-12-10, 16:49
好的,这是MATLAB中的一些代码:

data = [1 1.5 2 3 4 4.5 5 6 7 7 7 0 0 0]; histc(data, [1:1:5]) histc(data, [1:1:5, inf]) histc(data, [-inf, 1:1:5]) 输出以下内容:

ans = 2 1 1 2 1 ans = 2 1 1 2 5 0 ans = 3 2 1 1 2 1 我的问题是,当在bin大小中使用inf时,为什么MATLAB返回一个无用的0(在这种情况下表示> = 5)?

永远不是零吗?帮助说输出将始终与容器大小相同,但是在这种情况下这不是一个不好的规格吗?


回答:
这实际上是HISTC (http://www.mathworks.com/access/helpdesk/help/techdoc/ref/histc.html)的正确行为。使用语法时:

n = histc(x,edges); 然后,从文档中:

<blockquote>
如果edges(k)