我正在尝试编写一个非常简单的 mex 文件,假设只是为了尝试它的工作方式。我浏览了很多材料,我读的越多,我就越困惑。我需要它来进一步编写与外部硬件交互的 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("NAMEn");