I am trying to to write a very simple mex file, let's say just to try out the way it works. I have gone through a lot of materials and more I read, more I get confused. I need this to further write a mex file that interacts with external hardware. Please help!
// 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 file - test.m //
sprintf ('WELCOME')
printing()
When i run the test.m file, I would like to see WELCOME NAME 20 However I see only welcome. I understand that I have not updated the plhs[] array. But all I want to do is execute something inside mexFunction.Why wouldn't the cout inside name() and age() achieve this?
Also, how do i confirm that name() and age() are executed?
The call to cout
will not print to the MATLAB console, you need to use the MEX printf function.
mexPrintf("NAME\n");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With