Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert Matlab Handle class to C++

Tags:

c++

matlab

I have a handle class in Matlab that I want to be able to use in C++. I already learned here that I can't just generate a C++ class, but have to wrap my class with functions. The example in the other question only shows the use of one member function in a wrapper function. However, I need to be able to call several member functions of my class.

As I cannot pass my class instance to the wrapper functions as per the Matlab documentation, I don't see a way of having several functions operate on the same object.

Is it not possible to do this?

Any help is appreciated.

like image 993
Nicolas Avatar asked Dec 12 '25 22:12

Nicolas


1 Answers

You cannot have classes as input and output for the main function for which you generate code. But you can have any number of sub-functions called from your main function which can take the object as input. The object is typically created from your main function and passed to your sub-functions. You then generate code using codegen "main function name". The generated code contains all the sub-functions.

You also should use coder.inline('never') in your sub-functions so that they show up as separate functions in generated code.

like image 161
Navan Avatar answered Dec 15 '25 10:12

Navan