Legacy code, c++ class

1 次查看(过去 30 天)
Ahmet Tuna
Ahmet Tuna 2017-5-26
回答: Archita P 2017-5-31
Hi,
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

回答(1 个)

Archita P
Archita P 2017-5-31
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- https://www.mathworks.com/help/simulink/sfg/s-function-examples.html
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-
https://www.mathworks.com/help/simulink/sfg/integrating-existing-c-functions-into-simulink-models-with-the-legacy-code-tool.html
But, the Legacy Code Tool can interface with C++ functions, but not C++ objects.

类别

Help CenterFile Exchange 中查找有关 Write C Functions Callable from MATLAB (MEX Files) 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by