一种获得离散型周期数据的变化周期的算法
创始人
2024-02-16 07:39:41
0

400个数据像这样:
152 155 155 237 24 27 27 109 152 155 155 237 24 27 27 109 152 155 155 237 24 27 27 109 152
155 155 237 24 27 27 109 152 155 155 237 24 27 27 109 152 155 155 237 24 27 27 109 152 155
155 237 24 27 27 109 152 155 155 237 24 27 27 109 152 155 155 237 24 27 27 109 152 155 155
237 24 27 27 109 152 155 155 237 24 27 27 109 152 155 152 237 24 27 27 109 152 155 155 237
24 27 27 109 152 155 155 237 24 27 27 109 152 155 155 237 24 27 27 109 152 155 155 237 24
27 27 109 152 155 155 237 24 27 27 109 152 155 155 237 24 27 27 109 152 155 155 237 24 27
27 109 152 155 155 237 24 27 27 109 152 155 155 237 24 27 27 109 152 155 155 237 24 27 27
109 152 155 152 237 24 27 27 109 152 155 155 237 24 27 27 109 152 155 155 237 24 27 27 109
152 155 155 237 24 27 27 109 152 155 155 237 24 27 27 98 152 152 155 237 24 27 27 109 152
155 155 237 24 27 27 98 152 155 155 237 24 27 27 109 152 152 155 226 24 27 27 98 152 152
155 226 24 27 27 98 152 152 155 226 24 24 27 98 152 152 155 226 24 24 27 98 152 152 155
226 24 24 27 98 152 152 155 226 24 24 27 98 152 152 155 226 24 27 27 98 152 152 155 226
24 27 27 98 152 155 155 226 24 27 27 98 152 155 155 226 24 27 27 98 152 155 155 226 24
27 27 98 152 155 155 226 24 27 27 98 152 152 155 226 24 24 27 98 152 152 155 226 24 24
27 98 152 152 155 226 24 24 27 98 152 152 155 226 24 24 27 98 152 152 155 226 24 24 27
98 152 152 155 226 24 24 27 98 152 152 155 226 24 27 27 98 152 152 155 226 24 27 27 98
曲线像这样:
在这里插入图片描述
问,怎么求该离散型数据的变化周期?
答案:迭代,方差。
算法如下:

#include 
#include   
#include 
#include 
#include 
using namespace std;
#define ARRAYLEN 24
#define TOTAL_SAMPLES 400
int main(){int samples_Data[TOTAL_SAMPLES];ifstream infile("test.txt");string data;int count_samples_Data=0;while (getline(infile, data)) {//cout<< data << endl;//string str = "92 20 120.7";int num1 = 0, num2 = 0, num3 = 0,num4 = 0, num5 = 0, num6 = 0,num7 = 0, num8 = 0, num9 = 0,num10 = 0, num11 = 0, num12 = 0,num13 = 0, num14 = 0, num15 = 0,num16 = 0, num17 = 0, num18 = 0,num19 = 0, num20 = 0, num21 = 0,num22 = 0, num23 = 0, num24 = 0,num25 = 0;istringstream string_to_num(data);string_to_num >>num1 >> num2 >> num3 >>num4 >> num5 >> num6 >>num7 >> num8 >> num9 >>num10 >> num11 >> num12 >>num13 >> num14 >> num15 >>num16 >> num17 >> num18 >>num19 >> num20 >> num21 >>num22 >> num23 >> num24 >>num25 ;samples_Data[count_samples_Data]=num1;samples_Data[count_samples_Data+1]=num2;samples_Data[count_samples_Data+2]=num3;samples_Data[count_samples_Data+3]=num4;samples_Data[count_samples_Data+4]=num5;samples_Data[count_samples_Data+5]=num6;samples_Data[count_samples_Data+6]=num7;samples_Data[count_samples_Data+7]=num8;samples_Data[count_samples_Data+8]=num9;samples_Data[count_samples_Data+9]=num10;samples_Data[count_samples_Data+10]=num11;samples_Data[count_samples_Data+11]=num12;samples_Data[count_samples_Data+12]=num13;samples_Data[count_samples_Data+13]=num14;samples_Data[count_samples_Data+14]=num15;samples_Data[count_samples_Data+15]=num16;samples_Data[count_samples_Data+16]=num17;samples_Data[count_samples_Data+17]=num18;samples_Data[count_samples_Data+18]=num19;samples_Data[count_samples_Data+19]=num20;samples_Data[count_samples_Data+20]=num21;samples_Data[count_samples_Data+21]=num22;samples_Data[count_samples_Data+22]=num23;samples_Data[count_samples_Data+23]=num24;samples_Data[count_samples_Data+24]=num25;count_samples_Data+=25;//cout << num1 <<" "<< num2 <<" "<< num3 <<" "<0.0};int count=0;for (omiga=0;omigacount=0;for (count =0 ;count<5;count++){datas[count]=samples_Data[startIndex+count*(omiga+1)];}//计算datas 五个数据的方差tempSum=0.0;for (count =0 ;count<5;count++){tempSum+=datas[count];}tempAvg=(double)(tempSum/5);tempSum=0.0;for (count =0 ;count<5;count++){tempSum+=(datas[count]-tempAvg)*(datas[count]-tempAvg);}fangcha=(double)(tempSum/5);fangchaArray[omiga]=fangcha;}fangcha=fangchaArray[0];double preDaoShu=0.0;double postDaoShu=0.0;for (omiga=0;omigaif (fangcha>fangchaArray[omiga]){fangcha=fangchaArray[omiga];loopT=omiga+1;}}cout<<"loopT:  "< 这个头文件。istringstream类用于执行C++风格的串流的输入操作。
istringstream对象可以绑定一行字符串,然后以空格为分隔符把该行分隔开来。在读取数据文件时可以按行读取数据并存储到字符串中,然后通过istringstream字符串分割开,并存储到相应类型的变量中。语法格式如下:istringstream::istringstream(string str);
1
将一个字符串中数字分割开并赋值给double类型的变量:string str = "92 20 120.7";
double num1 = 0, num2 = 0, num3 = 0;
istringstream string_to_num(str);
string_to_num >> num1 >> num2 >> num3 ;
cout << num1 << endl << num2 << endl << num3 ;
————————————————
版权声明:本文为CSDN博主「还是要努力呀!」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_33021529/article/details/115462166
*/

相关内容

热门资讯

喜欢穿一身黑的男生性格(喜欢穿... 今天百科达人给各位分享喜欢穿一身黑的男生性格的知识,其中也会对喜欢穿一身黑衣服的男人人好相处吗进行解...
发春是什么意思(思春和发春是什... 本篇文章极速百科给大家谈谈发春是什么意思,以及思春和发春是什么意思对应的知识点,希望对各位有所帮助,...
网络用语zl是什么意思(zl是... 今天给各位分享网络用语zl是什么意思的知识,其中也会对zl是啥意思是什么网络用语进行解释,如果能碰巧...
为什么酷狗音乐自己唱的歌不能下... 本篇文章极速百科小编给大家谈谈为什么酷狗音乐自己唱的歌不能下载到本地?,以及为什么酷狗下载的歌曲不是...
家里可以做假山养金鱼吗(假山能... 今天百科达人给各位分享家里可以做假山养金鱼吗的知识,其中也会对假山能放鱼缸里吗进行解释,如果能碰巧解...
华为下载未安装的文件去哪找(华... 今天百科达人给各位分享华为下载未安装的文件去哪找的知识,其中也会对华为下载未安装的文件去哪找到进行解...
四分五裂是什么生肖什么动物(四... 本篇文章极速百科小编给大家谈谈四分五裂是什么生肖什么动物,以及四分五裂打一生肖是什么对应的知识点,希...
怎么往应用助手里添加应用(应用... 今天百科达人给各位分享怎么往应用助手里添加应用的知识,其中也会对应用助手怎么添加微信进行解释,如果能...
苏州离哪个飞机场近(苏州离哪个... 本篇文章极速百科小编给大家谈谈苏州离哪个飞机场近,以及苏州离哪个飞机场近点对应的知识点,希望对各位有...
客厅放八骏马摆件可以吗(家里摆... 今天给各位分享客厅放八骏马摆件可以吗的知识,其中也会对家里摆八骏马摆件好吗进行解释,如果能碰巧解决你...