以一个数组,并改变其价值观有一个新的最小值和最大值 [英] Take an array and transform its values to have a new minimum and maximum

查看:108
本文介绍了以一个数组,并改变其价值观有一个新的最小值和最大值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有数据,在一列的数组长度 354717 。值不等12.8 (分钟)和 64.2 (最大)。

I have an array of data in a column with length 354717. The values vary between 12.8 (min.) and 64.2 (max.).

我要创建相同大小的用分钟值的数组。= 2.7 最大= 27

I want to create an array of the same size with values of min.= 2.7 and max.= 27.

有什么建议?

推荐答案

您可以先归一化数据,使动态范围落在之间[0,1] 。一旦你这样做,你可以乘以你的价值观 27 - 2.7 = 24.3 ,然后通过抵消这种 2.7 来获得之间的数值[2.7,27] 。换句话说,如果你的数组称为 A ,做到这一点:

You can first normalize the data so that the dynamic range falls between [0,1]. Once you do this, you can multiply your values by 27 - 2.7 = 24.3, then offset this by 2.7 to get your values between [2.7, 27]. In other words, if your array is called A, do this:

normA = (A - min(A)) / (max(A) - min(A)); %// Normalize to [0,1].
out = 24.3*normA + 2.7; %// Change to [2.7, 27]

在一般情况下,如果你想获得你的数据是在一定范围内,第一次正常化像code的第一行数据,那么这样做:

In general, if you want to get your data to be within a certain range, first normalize your data like in the first line of code, then do this:

out = (maxD - minD)*normA + minD;

记住,诺玛为归一化数据,使其落在之间[0,1] MIND MAXD 是最低的,你想所需范围的最大值。对于你的情况,介意= 2.7 MAXD = 27

Remember, normA is the normalized data so that it falls between [0,1]. minD and maxD are the minimum and maximum values of the desired range you want. For your case, minD = 2.7 and maxD = 27.

祝你好运!

这篇关于以一个数组,并改变其价值观有一个新的最小值和最大值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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