MATLAB Answers

Legacy code, c++ class

2 views (last 30 days)
Ahmet Tuna
Ahmet Tuna on 26 May 2017
Answered: Archita P on 31 May 2017
I have c++ class. I want to use this c++ class in matlab/simulink. How I can do this ? i read something about legacy code but i didnt understand. Please help me. Thanks a lot.
Best regards

Answers (1)

Archita P
Archita P on 31 May 2017
Enter the following command in the MATLAB command window-
>> sfundemos
It has examples for C++ integration.
You can refer to the following link for more information-
You can also use a MEX file to construct a new instance of the C++ object and return a pointer to it in MATLAB by encoding the pointer in an int64 matrix for example. Then you can pass this matrix back to the same or a different MEX file that will decode it and use it. You could use a MATLAB class to encapsulate the MEX files that use the C++ class and the encoding of the C++ pointer. A handle class destructor could be used to call a MEX file that deletes the C++ object.
An example of this approach can be found in the following file exchange link-
You can also use the legacy code tool to integrate C functions with MATLAB. Refer to the link mentioned below for more information-
But, the Legacy Code Tool can interface with C++ functions, but not C++ objects.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by