MATLAB: How to pass MWStructArray arrays of size greater than 1-by-1 from C++ into a MATLAB Builder for .NET 2.2 (R2007a) component

MATLAB Builder NE

I would like to pass MATLAB Structure arrays of size greater than 1-by-1 from a C++ driver application to a MATLAB Builder for .NET component and back.

Best Answer

The attached ZIP-file contains an example Microsoft Visual Studio 2005 project that contains the CPP-file calling the .NET object. This example demonstrates some simple operations on multi-element structures.
To build the application, follow the steps detailed below:
1. Execute
mbuild -setup
at the MATLAB command prompt and select a supported C/ C++ compiler such as Microsoft Visual Studio 2005. Note that the LCC compiler cannot be used to build the component.
2. Launch DEPLOYTOOL by typing
DEPLOYTOOL
at the MATLAB command prompt.
3. Create a new project by selecting "File -> New Project" menu item and enter the component name as 'StructArrayComp'. This will also create the class StructArrayCompclass.
4. Once you are returned to the MATLAB Builder window, highlight the component, click the "Add File" button and add MATLAB files\DISPSTRUCT1.M and MATLAB files\MODSTRUCT.M
5. Select "Build -> .NET object" from the menu to build the .NET object.
6. Open 'MWArrayExample' in Visual Studio.
8. In the Solution Explorer tab, right-click on 'MWArrayExample' and choose "Add Reference...". Add references to the above component as well as to the file MWArray.dll. This file is located in $MATLAB/bin/win32 (where $MATLAB is the MATLAB root directory on your machine, as returned by typing
matlabroot
at the MATLAB command prompt.)
9. Select "Build -> Build Solution" from the menu and then execute the application. You should see a variety of structure contents printed to the Command Prompt.