取平均值并保存为no-1,no-2,no-3等 [英] Take average and save it as no-1, no-2, no-3, etc

查看:48
本文介绍了取平均值并保存为no-1,no-2,no-3等的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我这里有浮点数

0 0 0 0 0 120 145 154 254 254 156 0 0 0 0 0 0 14 15 12 85 65 85 78 0 0 0 0 0 0 0 965 985 785 123 654 784 965 325 0 0 0 0 0 0 0 0 .........





在上述情况下我必须取平均值120 145 154 254 254 156并保存为Number-1

和另一套14 15 12 85 65 85 78相同并保存为number-2等等。



这个或C#代码背后的逻辑可能对我有什么帮助?



我尝试了什么:



没有尝试任何东西......卡在这里。

I have float array here
0 0 0 0 0 120 145 154 254 254 156 0 0 0 0 0 0 14 15 12 85 65 85 78 0 0 0 0 0 0 0 965 985 785 123 654 784 965 325 0 0 0 0 0 0 0 0.........


In the above case I have to take average of 120 145 154 254 254 156 and save as Number-1
and same for the other set for 14 15 12 85 65 85 78 and save as number-2 and so on.

What is logic behind this or code in C# maybe which can help me?

What I have tried:

didnt try anything...stuck here.

推荐答案

这有很多关于它的作业气味,所以没有代码!

首先查看数据:猜测你想要将零之间的值相加。

所以第一步是识别数据。

这很简单:设置一个List以保持你的平均值,并创建一个bool,这样你就可以知道你是否在组装平均值,和两个v alues:一个总计和一个计数。

设置一个循环来查看数组中的每个值。

在循环中,查看值。

如果它为零,那么看看组装布尔。

如果您正在组装,则将总数除以计数,并将该值添加到列表中。重置总数和计数,并将bool设置为not assembling。否则,忽略它。

如果值不为零,则将值添加到总计,并递增计数。将bool设置为组装。



在循环结束时,将任何最终值添加到列表中。

您现在的列表包含每个平均值作为单独的数字。
This has a lot of a "homework" smell about it, so no code!
Start by looking at the data: at a guess you want to sum the values between zeros.
So the first step is to identify the data.
That's pretty simple: set up a List to hold your averages, and create a bool so you can tell if you are assembling averages or not, and two values: a total, and a count.
Set up a loop to look at each value in the array.
In the loop, look at the value.
If it's zero, then look at the "assembling" bool.
If you are assembling, then divide the total by the count, and add that value to the list. Reset the total and count, and set the bool to "not assembling". Otherwise, ignore it.
If the value isn't zero, add the value to the total, and increment the count. Set the bool to "assembling".

At the end of the loop, add any final value to the list.
Your list now contains each of the averages as separate numbers.


这篇关于取平均值并保存为no-1,no-2,no-3等的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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