Legacy code, c++ class
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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
0 commentaires
Réponses (1)
Archita P
le 31 Mai 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- 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.
0 commentaires
Voir également
Catégories
En savoir plus sur Write C Functions Callable from MATLAB (MEX Files) dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!