This change has been incorporated into the documentation in Release 2009a (R2009a). For previous releases, read below for any additional information:
The type mismatch error is due to the type of the variable (DataJ) that is used to hold the value returned by MLGETVAR command. The variable that is created by MATLAB to hold the value when MLGETVAR returns is of type Variant() - that is, it is an array of Variants.
Since the returned variable DataJ is an array, it must be indexed in order to use the values it contains. Thus, the call to MsgBox should be coded as follows if the variable J in the MATLAB workspace is a scalar:
This will cause the VBA code to run without error.
Likewise, if J is a matrix of dimension MxN in the MATLAB workspace, you can index into the corresponding (m,n)-th element in DataJ with the following statement:
All other VBA array conventions apply.
A similar example of indexing into a Variant() variable as returned by MLGETVAR can be found in the following Spreadsheet Link EX example in the documentation:
If you have installed the help documentation, you may access the same page locally by typing the following at the MATLAB prompt:
web([docroot,'/toolbox/exlink/f2-2311.html#brfcgkq'])
Best Answer