twirls/CommonLib/matlab_io.h

34 lines
1.0 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

/*********************************************************************************************
Description: 提供基本matlab读写数据功能
Copyright : All right reserved by ZheYuan.BJ
Author : Zhang Zhonghai
Date : 2023/09/18 adfasdf
***********************************************************************************************/
#ifndef __MATLAB_IO_H
#define __MATLAB_IO_H
#include <string>
#include <mat.h>
#include <vector>
using namespace std;
#define STRING_BUF_SIZE 10240
typedef double T;
/*
注意参数的区别,读取时候直接传递文件路径名,写入的时候需要提供文件指针,
这是因为写入的时候可能一次性需要写入多个矩阵
*/
/* 读取字符串矩阵 */
bool ReadMtxString(const string& filePath, const string& mtxName, vector<string>& vStr, int* pRowNum, int* pColNum);
/* 从mat文件中读取给定名称的矩阵数据并获取矩阵的行列数值 */
T* ReadMtxDouble(const string& filePath, const string& mtxName, int* pRowNum, int* pColNum);
/* 将数据写入mat文件中用给定的名称命名 */
bool SaveMtxDouble(T* src, MATFile* pMatFile, string matrixName, int rowNum, int colNum);
#endif