实施移动平均线? [英] implementing moving average?

查看:74
本文介绍了实施移动平均线?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

制作一个模拟DAQ功能的简单程序。我有7个模拟和3个数字传感器。我有一个主类Form1.cs和一个Sensorclass为我提供了传感器的随机模拟和数字值。

Making a simple program that simulates functions of a DAQ. I have 7 analog and 3 digital sensors. I have a main class Form1.cs and a Sensorclass provides me the random analog and digital values for the sensors.

现在我正在尝试创建一个移动平均滤波器,我几乎已经完成了它它只是当我试图从Windows窗体中的文本框中取出最后5个生成值的移动平均值时,我从不同的传感器获取值。我需要每个传感器平均移动

Now I am trying to create a moving average filter and I have almost done it , its just that when I tried to take moving average off the last 5 generated values from a text box I have in Windows form,I get values from different sensors. I need to take moving average of each individual sensor.

为了更好地解决问题,请参见下文。

To give a better impression of the problem see below.

这是我的数据如何在文本框中显示

This is how my data is displayed in the textbox

时间戳      AI.1      AI.2      AI.3      AI.4      AI.5   
AI.6      AI.7 


13:29:05.091  0.726    0.249    0.771    0.294    0.816    0.338    0.861 

13:30:40.325  0.817    0.111    0.404    0.698    0.991    0.284    0.962 

13:31:19.709  0.768    0.467    0.166    0.865    0.564  0.263    0.915

13:32:00.943  0.558    0.772    0.985    0.198    0.412    0.625    0.594

13:32:31.391  0.206    0.658    0.109    0.560    0.012 NBSP;   0.463    0.720

该程序会计算文本框中最后五个数字的平均值,这意味着移动平均线=(0.109 + 0.560 + 0.012 + 0.463 + 0.720)/5=0.373。

而AI.1的移​​动平均值为:(0.726 + 0.817) + 0.758 + 0.558 + 0.206)/5=0.615

这显然很明显错误,因为我得到了来自不同传感器的平均值。 

我需要传感器AI.1,AI2,......等的最后五个值的平均值

所以我需要做一些更改才能完成这项工作。

这是我的主代码,

 

推荐答案

这里的代码实在太多了。它听起来像归结为你在文本框中找到正确的数据时遇到问题。为此,我会说这是因为你试图使用文本框来实现它不适合的东西。

There is really too much code there to go through. What it sounds like it boils down to is you're having an issue finding the correct data in a textbox. For that I'd say it is because you are trying to use a textbox for something it isn't designed for.

首先,您不应该尝试从UI控件中解析出非用户输入。这没有意义。将数据存储在代码中,就像从数据库或文件中读取数据一样。用户界面应该负责渲染您已经拥有的数据。这立即消除了大多数问题。

Firstly you shouldn't try to parse out non-user input from a UI control. That doesn't make sense. Store your data in your code like you would have if you were reading it from a database or a file. The UI should just be responsible for rendering data you already have. This eliminates most problems immediately.

其次,文本框用于存储任意文本,而不是"表格"。价值观从文本框切换到DataGridView(甚至是ListView),使用"行"和"行"将变得非常容易。和"列"
中的数据需要对UI事件作出反应的几种情况。

Secondly, a textbox is for storing arbitrary text, not a "table" of values. Switch from a textbox to a DataGridView (or even a ListView) and it will become dramatically easier to work with the "rows" and "columns" of data in the few cases where you need to react to UI events.

将数据移入内存并切换到DGV之后我认为你是个问题找不到正确的数据将不存在。

Once you've moved your data into memory and switched to a DGV I think you're issue with finding the correct data will be non-existent.


这篇关于实施移动平均线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆