I want to access the properties of a custom MATLAB class in a MAT-file in a C++ standalone application. The custom class is a class created in MATLAB with something like this:
classdef customClass
properties
myProp
end
methods
function obj = customClass(arg1,arg2)
obj.myProp = arg1 + arg2
end
end
end
An instance of this class is now saved to a MAT-file and should be accessed by a standalone C application.
Apparently, MATLAB offers a library for reading MAT-files in C applications.
This works fine for the "normal" types and the API seems to offer the function mxGetProperty
for accessing custom objects. However, if I try to run a minimal example using this function, it fails with an empty assertion in management.cpp:671
. The minimal example is:
#include <iostream>
#include "mat.h"
int main()
{
MATFile* file = matOpen("test.mat", "r");
if (file == nullptr)
std::cout << "unable to open .mat" << std::endl;
mxArray* customClass = matGetVariable(file, "c");
if (customClass == nullptr)
std::cout << "unable to open tcm" << std::endl;
mxArray* prop = mxGetProperty(customClass, 0, "myProp");
if (prop == nullptr)
std::cout << "unable to access myProp";
}
A closer look to the documentation reveals the limitation:
mxGetProperty
is not supported for standalone applications, such as applications built with the MATLAB engine API.
Is there any other possibility to access a customClass
in a MAT-file from a standalone C++ application?