用于双精度数据一维数组的简单 ANSI C 直方图函数?

发布于 2024-12-20 02:19:29 字数 192 浏览 1 评论 0原文

是否有通用的解决方案可以从输入的一维双精度数据数组创建数据的一维直方图数组?

我不想在 C 中绘制直方图,我只需要通过对数据进行分箱来创建直方图一维数组。

有人可以帮助我理解 C 中的分箱(例如循环)代码是什么样子吗?假设最小和最大数据点已知,并且我们希望使用不同 bin 的可变数量(例如 hist_pts)。

Is there a generic solution out there to create a 1-D histogram array of data from an input 1-D array of double-precision data?

Not looking to plot the histogram in C, I just need something to create the histogram 1-D array by binning the data.

Could someone help me understand what the binning (e.g. loop) code may look like in C? Assume the min and max data points are known and we want to use a variable number (e.g. hist_pts) of different bins.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

寂寞陪衬 2024-12-27 02:19:29
int* bin = calloc(hist_pts,sizeof(int));
float interval = (float)(max - min ) / num_bins;
for (i=0;i<N;i++)
    bin[ (int)((value[i]- min)/interval) ]++;
//don't forget to `free(bin) after you use it.
int* bin = calloc(hist_pts,sizeof(int));
float interval = (float)(max - min ) / num_bins;
for (i=0;i<N;i++)
    bin[ (int)((value[i]- min)/interval) ]++;
//don't forget to `free(bin) after you use it.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文