MATLAB: Do I receive the warning “variable ‘x’ of class ‘struct’ contains nonsaveable members” when using a shared library created with MATLAB Compiler to save a structure created in C++

MATLAB Compiler

I created a MATLAB structure in my C++ program that calls a shared library created with MATLAB Compiler. In C++, I create the structure using the following code:
int dims[2] = {1,1};
const char* fields[] = {"combinations"};
mwArray Input_struct(2, dims, 1,fields);
mwArray comb_struct;
Input_struct.Get("combinations",2, 1, 1).Set(comb_struct);
I attempt to save this structure to a MAT-file after passing it to the MATLAB DLL. The structure is not saved and I receive the warning
Warning: Variable 'x' of class 'struct'
cannot be saved to a MAT-file or contains nonsaveable members.
Skipping...
However, if I print out information about all the members of x before attempting to save the variable, they all appear to be fine.

Best Answer

The ability to save a variable or field of a structure that does not have an explicitly declared type is not available in MATLAB. Other functions in MATLAB may read the contents as empty.
This warning message can appear if one of the structures fields was created but not set to any type. Instead, declare the variable to be of the desired type. For example:
mwArray comb_struct(mxDOUBLE_CLASS);