Writing an extremely basic mex function in matlab

I am trying to write a very simple mex file, let's just try how it works. I read a lot of materials and read more, more embarrassed. I need this to further write the mex file, which interacts with external equipment. 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 a greeting. I understand that I did not update the plhs [] array. But all I want to do is do something inside mexFunction.Why would cout inside name () and age () achieve this?

Also, how can I confirm that the names () and age () are executed?

+5
source share
1 answer

The cout call will not be displayed on the MATLAB console, you need to use the print function MEX.

 mexPrintf("NAME\n"); 
+5
source

All Articles