在C频率直方图 [英] Frequency Histogram in C
问题描述
有人可以给我一个直方图的伪code会怎么看起来像一个暗示?
can someone give me a hint on how a histogram's pseudo code would look like?
推荐答案
如何构建并填写直方图?
How to structure and fill a histogram?
简单的情况就是每个二进制计数:
Trivial case is just a count per bin:
/* needs error checking, badly */
int *buildHist(int bins, double min, double max, int n, double *data){
double *hist=malloc(bins*sizeof(int));
if (hist == NULL) return hist;
for (int i=0; i<n; ++i){
int bin=int( (data[i]-min)/((max-min)/(bins)) );
if ( (bin>=0) && (bin<n) ) hist[bin]++;
}
return hist;
}
有关的加权直方图,数组必须是浮点类型的。
For a weighted histogram, the array must be of floating point type.
随着越来越多的数据(大于和小于流计数,累加统计......甚至保持在同一个地方作为计数的限制),使用包括阵列的结构。
With more data (over- and under-flow counts, accumulated statistics...or even to keep the limits in the same place as the count), use a structure that includes the array.
增量填充经常需要的,但应该是显而易见的,从这里。
Incremental filling is often desired, but should be obvious from here.
输出取决于大量你手头有什么样的显示技术。
Output depends a great deal on what display technology you have at hand.
这篇关于在C频率直方图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!