MATLAB: How to use MLGetMatrix and MLPutMatrix in a Macro Function or Macro Subroutine

functionmacromlgetmatrixmlputmatrixSpreadsheet Linksubroutine

I receive the following error while using MLGetMatrix or MLPutMatrix:
Visual Basic Error
Object Required Error 424

Best Answer

Here is an example of a macro subroutine that uses MLGetMatrix:
Sub Test1()
MLGetMatrix "X", "Sheet1!A5"
MatlabRequest
End Sub
NOTE: The name of the sheet, Sheet1, is used here so that the location where the data is put is assured to be in the intended worksheet. Please make sure that the matrix that you want to import into Excel exists in the MATLAB Workspace before running the macro.
Here is an example of a macro subroutine that uses MLPutMatrix:
Sub Test2()
MLPutMatrix "A", Range("A1:C3")
End Sub
NOTE: The Range function is needed here due to VBA for Excel requirement. Before running this example, please make sure that there are values in cell range A1:C3.