42 lines
934 B
C++
42 lines
934 B
C++
|
#include "MatlabObject.h"
|
|||
|
|
|||
|
#include <QTextCodec>
|
|||
|
|
|||
|
#include <MatlabEngine.hpp>
|
|||
|
#include <MatlabDataArray.hpp>
|
|||
|
|
|||
|
using namespace matlab::engine;
|
|||
|
|
|||
|
MatlabObject::MatlabObject(QObject *parent)
|
|||
|
: QObject(parent)
|
|||
|
{
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
MatlabObject::~MatlabObject()
|
|||
|
{
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
void MatlabObject::RunMatlabFile(const QString& strFile)
|
|||
|
{
|
|||
|
QString strMatlabRun = QString("run('%1')").arg(strFile);
|
|||
|
|
|||
|
QTextCodec* code = QTextCodec::codecForName("utf-8");
|
|||
|
std::string strRun = code->fromUnicode(strMatlabRun.toUtf8().data()).data();
|
|||
|
|
|||
|
std::u16string utf16_str = string2u16string(strRun);
|
|||
|
// <20><><EFBFBD><EFBFBD>MATLAB Engine
|
|||
|
std::unique_ptr<MATLABEngine> matlabPtr = startMATLAB();
|
|||
|
// <20><><EFBFBD><EFBFBD>M<EFBFBD>ļ<EFBFBD>
|
|||
|
matlabPtr->eval(utf16_str);
|
|||
|
}
|
|||
|
|
|||
|
std::u16string MatlabObject::string2u16string(std::string& str)
|
|||
|
{
|
|||
|
std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> convert;
|
|||
|
std::u16string utf16_str = convert.from_bytes(str);
|
|||
|
|
|||
|
return utf16_str;
|
|||
|
}
|