I'm writing a C# program that needs to call MATLAB processing routines. I've been looking at MATLAB's COM interface. Unfortunately, the COM interface appears to be rather limited in terms of the types of data that can be exchanged. Matrices and character arrays are supported, but there doesn't seem to be support for exchanging struct data or cell arrays between C# and MATLAB using the COM interface. For example, in the following code (assuming that a DICOM image named IM000000 is present in the appropriate file folder), the MATLAB variables 'img' and 'header' are a 256x256 int16 matrix and a struct, respectively. The GetWorkspaceData call works fine for 'img', but returns null for 'header' because 'header' is a struct.
public class MatlabDataBridge
{
MLApp.MLAppClass matlab;
public MatlabDataBridge()
{
matlab = new MLApp.MLAppClass();
}
public void ExchangeData()
{
matlab.Execute(@"cd 'F:\Research Data\'");
matlab.Execute(@"img = dicomread('IM000000');");
matlab.Execute(@"header = dicominfo('IM000000');");
matlab.GetWorkspaceData(@"img", "base", out theImg); // correctly returns a 2D array
matlab.GetWorkspaceData(@"header", "base", out theHeader); // fails, theHeader is still null
}
}
Is there a suitable workaround for marshalling struct data to/from MATLAB using the COM interface? If not, is this functionality well supported by the MATLAB Builder NE add-on?