我正在尝试编写一个非常简单的 mex 文件,假设只是为了尝试它的工作方式。我浏览了很多 Material ,阅读的越多,我就越困惑。我需要它来进一步编写一个与外部硬件交互的 mex 文件。请帮忙!
// header file - printing.h //
#include<iostream>
class printing
{
public:
void name();
void age();
};
// cpp file - printing.cpp //
#include<iostream>
#include "mex.h"
#include "matrix.h"
#include "printing.h"
#include <string>
using namespace std;
void mexFunction(int nlhs, mxArray*plhs[],
int nrhs, const mxArray *prhs[])
{
printing p1;
p1.name();
p1.age();
}
void printing::name()
{
cout << "NAME" << endl;
}
void printing::age()
{
cout << "20" << endl;
}
//.m 文件 - test.m//
sprintf ('WELCOME')
printing()
当我运行 test.m 文件时,我想看看 欢迎 姓名 20 但是我只看到欢迎。我知道我没有更新 plhs[] 数组。但我只想在 mexFunction 中执行一些操作。为什么 name() 和 age() 中的 cout 不能实现这一点?
另外,如何确认 name() 和 age() 被执行?
最佳答案
cout
的调用不会打印到 MATLAB 控制台,您需要使用 MEX printf 函数。
mexPrintf("NAME\n");
关于c++ - 在 matlab 中编写一个非常基本的 mex 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37559363/