readfrommat.h

来自「his file contains a summary of what you 」· C头文件 代码 · 共 82 行

H
82
字号
/**************************************************************************
*  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 + =
减小字号Ctrl + -
显示快捷键?