⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 readfrommat.h

📁 his file contains a summary of what you will find in each of the files that make up your CC applica
💻 H
字号:
/**************************************************************************
*  ReadFromMat.h
*  说明:从Mat文件中读取数据,涉及到和Matlab接口编程的问题
*  2004,11.1 zya
**************************************************************************/

#include <iostream>
#include "mat.h"
#include "engine.h"
using namespace std;

extern const int length;

//从mat文件中读取数据
void readlorenz(const char* file, double *OutSeq)
{
	MATFile *pmat;
	mxArray *pa1;
	//mxArray *pa2,*pa3;
	Engine *ep;
	double lorenz[3*length];
	double lorenz_x[length];
	double lorenz_y[length];
	double lorenz_z[length];
	int i;
	double mean1=0;

	if (!(ep=engOpen(NULL)))
	{
		cout<<"Can't start the MATLAB engine!"<<endl;
	}
	pmat=matOpen(file,"r");
	if (pmat == NULL)
	{
		cout<<"Error open the mat file!"<<endl;
	}
	pa1=matGetVariable(pmat,"Y");
	if (pa1 == NULL)
	{
		cout<<"Error read the mat file!"<<endl;
	}
    //将matlab中的数据读入到数组lorenz中去
	memcpy((void *)lorenz, (void *)mxGetPr(pa1), sizeof(lorenz));

	for (i=0; i<length; i++)  //mat数据以行为先的形式存储,与c语言等数据存储方式不同
	{
		lorenz_x[i] = lorenz[i];
		lorenz_y[i] = lorenz[i+length];
		lorenz_z[i] = lorenz[i+2*length];
	}

	memcpy((double *)OutSeq, (double *)lorenz_x, sizeof(lorenz_x));

	
}

void ReadMatFrHenon(const char* file, double *OutSeq)
{
	MATFile *pmat;
	mxArray *pa;
	Engine *ep;
	double HyperHenon[length];

	if (!(ep=engOpen(NULL)))
	{
		cout<<"Can't start the MATLAB engine!"<<endl;
	}
	pmat=matOpen(file,"r");
	if (pmat == NULL)
	{
		cout<<"Error open the mat file!"<<endl;
	}
	pa=matGetVariable(pmat,"X");
	if (pa == NULL)
	{
		cout<<"Error read the mat file!"<<endl;
	}
    //将matlab中的数据读入到数组HyperHenon数组中去
	memcpy((void *)HyperHenon, (void *)mxGetPr(pa), sizeof(HyperHenon));
	memcpy((double *)OutSeq, (double *)HyperHenon, sizeof(HyperHenon));

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -