Hello,
I am binding my c++ toolsets to MATLAB. The code is very Object Oriented so I cannot just use simple mex functions and have to use clibgen.
Ideally I'd only need 2 functions: one that convert 1D MATLAB array into c++ vectors, and another one converting c++ vectors to 1D MATLAB array. The first eventually work (with data copy, not references), but getting a vector out does not.
Here is a simple example, on Windows with minGW installed through MATLAB:
// c++ code in main.hpp file:
#include "MatlabDataArray.hpp"
// DUmmy function adding 5 to an array
matlab::data::Array add5(std::vector<double> foo)
std::vector<double> bar(foo);
matlab::data::ArrayFactory fac;
return fac.createArray({bar.size()}, bar.begin(),bar.end());
library_files = [fullfile(matlabroot,"extern","lib","win64","mingw64","libMatlabDataArray.lib"),...
fullfile(matlabroot,"extern","lib","win64","mingw64","libMatlabEngine.lib")];
clibgen.generateLibraryDefinition("main.hpp",...
"OverwriteExistingDefinitionFiles",true, ...
"Libraries",library_files, ...
arr2 = clib.DAGGER.add5(arr);
arr2 is not a MATLAB array and cannot be used in simple operation with other arrays, or figures, ...
I get errors like that...
Operator '+' is not supported for operands of type 'clib.test.matlab.data.Array'
The real questions are: Is there a way, on the c++ side to return MATLAB arrays usable in MATLAB (eventually without data copy)? and is there an easy way to convert it back from MATLAB (although it would add a LOT of code overhead)?
Thanks in advance,
B.