如何在Processing/Arduino中计算统计模式
我是一名设计老师,试图帮助学生应对编程挑战,所以我编写代码是为了乐趣,但我不是专家。
她需要在使用构建的数据集中找到模式(最常见的值)来自连接到 Arduino 的传感器的数据,然后根据结果激活一些功能。
除了如何在 Arduino 中计算模式之外,我们已经弄清楚了大部分内容。我找到了帖子 获取在array 解决了 JavaScript 中的问题,但我无法“移植”它。
I'm a design teacher trying to help a student with a programming challenge, so I code for fun, but I'm no expert.
She needs to find the mode (most frequent value) in a dataset built using data from sensors coupled to an Arduino, and then activate some functions based on the result.
We've got most of it figured out, except how to calculate the mode in Arduino. I found the post Get the element with the highest occurrence in an array that solves the problem in JavaScript, but I haven't been able to "port" it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我使用了 HashMap 来替换 js {} 动态对象实例和浮动,但 @weberik 的端口看起来更简单。
您提到了传感器输入,所以我假设数据将被连续采样,因此可以以一定的间隔存储值,然后发送到该模式的处理。
只是一个疯狂的猜测,但她不是想平均/平滑传感器读数吗?
如果是这样,她可以在 Arduino 的数组中缓存一些值(比如 10 个),并在每次添加新值时获取平均值:
I've used a HashMap to replace the js {} dynamic object instance and floats, but @weberik's port looks more straightforward.
You've mentioned sensor input, so I presume data will be sampled continuously, so values could be stored at a certain interval, then sent to Processing for the mode.
Just a wild guess, but isn't she looking to average/smooth out sensor readings a bit?
If so, she could cache a few values (say 10) in an array in Arduino and get the average everytime a new values is added:
我将代码从您链接的帖子移植到处理,但仅限于int 数组。
我希望这有帮助。
I ported the code from your linked post to Processing, but it's limited to int arrays.
I hope that helps.