当前位置:网站首页>数据集中度分析,数据分布情况
数据集中度分析,数据分布情况
2022-07-23 15:03:00 【凌盛羽】
一、宏定义及头文件
#include <stdio.h>
#include <math.h>
#include <string.h>
#include<stdlib.h>
#include<time.h>
#ifndef u8
typedef unsigned char u8;
#endif
#ifndef u16
typedef unsigned short int u16;
#endif
#ifndef u32
typedef unsigned int u32;
#endif
#ifndef u64
typedef unsigned long long int u64;
#endif
#ifndef s8
typedef signed char s8;
#endif
#ifndef s16
typedef signed short int s16;
#endif
#ifndef s32
typedef signed int s32;
#endif
#ifndef s64
typedef signed long long int s64;
#endif
二、生成随机数
/******************************************************************************** * 函数名 : vGeneration_Random_Number * 描 述 : 生成随机数 * 输 入 : pDat : 源数据 * maxVal : 最大值 * minVal : 最小值 * num : 个数 ********************************************************************************/
void vGeneration_Random_Number(u16 * pDat, u16 maxVal, u16 minVal, u16 num)
{
u16 i = 0;
u16 dat = 0;
u16 temp = 0;
temp = maxVal - minVal + 1;
srand(time(NULL));
for (i = 0; i < num; ++i)
{
dat = (u16)((rand() % temp) + minVal);
*(pDat + i) = dat;
}
}
三、冒泡升排序
/* 冒泡升排序 */
void vBubble_RiseSort_U16(u16 * pDat, u16 len)
{
u16 i = 0, j = 0;
u16 temp = 0;
for (i = 0; i < (len - 1); i++)
{
for (j = (i + 1); j < len; j++)
{
if (*(pDat + j) < *(pDat + i))
{
temp = *(pDat + i);
*(pDat + i) = *(pDat + j);
*(pDat + j) = temp;
}
}
}
}
四、数据集中度分析
/******************************************************************************** * 函数名 : vConcentrate_Analyse * 描 述 : 数据集中度分析 * 输 入 : pDat : 源数据 * len : 数据长度 * startIndex : 开始索引 * gapVal : 相邻间隔数据值 * actCount : 有效最小数据量 ********************************************************************************/
void vConcentrate_Analyse(u16 * pDat, u16 len, u16 startIndex, u16 gapVal, u16 actCount)
{
u16 i = 0;
u16 num = 1;
u8 valid = 0;
u16 index = 0;
u16 start = 0;
//开始索引
start = index = startIndex;
for (i = start; i < len - 1; i++)
{
//有效相邻间隔值
if ((pDat[i + 1] - pDat[i]) <= gapVal)
{
num++;
valid = 1;
}
else
{
valid = 0;
}
if ((valid == 0) || (i == (len - 2)))
{
//有效最小数据量
if (num >= actCount)
{
printf("Index:%-3d Num:%-3d ==> ", index, num);
for (u16 x = index; x < (num + index); x++)
{
printf("[%02d]%-4d ", x, pDat[x]);
}
printf("\r\n");
}
index = i + 1;
num = 1;
}
}
}
五测试例程
int main(void)
{
#define DAT_NUM (20)
u16 Dat[20] = {
0};
u16 i = 0;
vGeneration_Random_Number(Dat, 500, 50, DAT_NUM);
vBubble_RiseSort_U16(Dat, DAT_NUM);
printf("Original Data:\r\n");
for (i = 0; i < DAT_NUM; i++)
{
if ((i) && (i%5==0))
printf("\r\n");
printf("[%02d]%-5d ", i, Dat[i]);
}
printf("\r\n\r\n");
printf("Concentrate Analyse:\r\n");
vConcentrate_Analyse(Dat, DAT_NUM, 2, 30, 3);
printf("Date: %s %s\r\n", __DATE__, __TIME__);
while (1);
return 0;
}
六、运行情况
开始运行...
Original Data:
[00]51 [01]76 [02]90 [03]107 [04]108
[05]118 [06]131 [07]154 [08]168 [09]268
[10]319 [11]357 [12]377 [13]383 [14]387
[15]421 [16]443 [17]448 [18]467 [19]478
Concentrate Analyse:
Index:2 Num:7 ==> [02]90 [03]107 [04]108 [05]118 [06]131 [07]154 [08]168
Index:11 Num:4 ==> [11]357 [12]377 [13]383 [14]387
Index:15 Num:5 ==> [15]421 [16]443 [17]448 [18]467 [19]478
Date: Jul 18 2022 13:42:47

开始运行...
Original Data:
[00]147 [01]150 [02]152 [03]183 [04]199
[05]201 [06]232 [07]236 [08]239 [09]248
[10]260 [11]272 [12]299 [13]304 [14]336
[15]353 [16]372 [17]381 [18]436 [19]499
Concentrate Analyse:
Index:3 Num:3 ==> [03]183 [04]199 [05]201
Index:6 Num:8 ==> [06]232 [07]236 [08]239 [09]248 [10]260 [11]272 [12]299 [13]304
Index:14 Num:4 ==> [14]336 [15]353 [16]372 [17]381
Date: Jul 18 2022 13:44:10

开始运行...
Original Data:
[00]74 [01]166 [02]187 [03]189 [04]189
[05]234 [06]264 [07]271 [08]281 [09]317
[10]319 [11]326 [12]326 [13]363 [14]377
[15]412 [16]416 [17]482 [18]486 [19]494
Concentrate Analyse:
Index:2 Num:3 ==> [02]187 [03]189 [04]189
Index:5 Num:4 ==> [05]234 [06]264 [07]271 [08]281
Index:9 Num:4 ==> [09]317 [10]319 [11]326 [12]326
Index:17 Num:3 ==> [17]482 [18]486 [19]494
Date: Jul 18 2022 13:45:13

边栏推荐
- 为啥一问 JVM 就 懵B ???
- Element content must consist of character data or tags with correct format
- 几何参数化重构
- Virtual machine network connection mode
- Date formatting
- ride the wind and waves! Digital transformation in the era of financial technology
- At least half of the people can't answer the difference between isempty and isblank
- Typescript empty array
- USB通信协议深入理解
- 线程池,我是谁?我在哪儿?
猜你喜欢

Food safety chocolate is also true or false? How much do you know about it

Console calculator developed based on C language

Detailed explanation of SQL bool blind note and time blind note

Leetcode skimming: dynamic planning 04 (different paths)

Food safety | what is the origin of plant meat that sounds very healthy?

Pymoo learning (3): use multi-objective optimization to find the set of optimal solutions

USB通信协议深入理解
一加OnePlus 10T的一系列规格在产品发布前被披露

Don't ask me again why MySQL hasn't left the index? For these reasons, I'll tell you all

What about the new retail e-commerce platform? Can we realize the digital transformation of traditional retail enterprises?
随机推荐
12 pictures +6k figure ZGC garbage collector and tuning skills
李宏毅《机器学习》丨7. Conclusion(总结)
工業物聯網中的時序數據
File management system based on OpenPGP
Aike AI frontier promotion (7.23)
【作业】研一(互联网新技术作业)
SAP HANA数据库备份失败解决办法
工业物联网中的时序数据
Detailed explanation of SQL error reporting and blind annotation
xlinx pcie xvc
Literature learning (part100) -- an introduction to autoencoders
From 5 seconds to 1 second, remember the performance optimization with "very" significant effect once
Food safety | ham sausage lunch meat, is it really so unbearable?
@Will multiple bean instances be created by multiple method calls of bean annotations
分析optimism重放合约地址攻击事件
Kv260 single board PS control setting IIC switch chip
基于C语言开发的控制台计算器
JS tool CECP
Virtual machine network connection mode
Use Preparedstatement to select and display recorded JDBC programs