Write contents of MATLAB matrix to Microsoft Excel worksheet
MLGetMatrix var_name, edat
out = MLGetMatrix(var_name,edat)
= MLGetMatrix( writes
the contents of MATLAB® matrix
the Excel® worksheet, beginning in the upper-left cell specified
edat. Use this syntax when working
directly in a worksheet.
Name of MATLAB matrix to access.
Worksheet location where the function writes the contents of
Write the contents of the MATLAB matrix
a 4-by-3 matrix, fill cells
C10..E13 with data:
Access the MATLAB matrix named by the string in worksheet
B12. Write the contents of the matrix to the
worksheet starting at the location named by the string in worksheet
MLGetMatrixin a VBA Macro
Write the contents of MATLAB matrix
the worksheet, starting at the cell named by
Sub Get_RangeA() MLGetMatrix "A", "RangeA" MatlabRequest End Sub
AddressProperty of the Range Object to Specify Location
In a macro, use the
Address property of the
range object returned by the VBA
to specify where to write the data:
Sub Get_Variable() MLGetMatrix "X", Cells(3, 2).Address MatlabRequest End Sub
Use this function to get the variable
A from MATLAB and
to test if the command succeeded:
Sub myfun() Dim out As Variant out = MLGetMatrix("A", "A1") If out <> 0 Then MsgBox out End If MatlabRequest End Sub
a message box with the error code.
If data exists in the specified worksheet cells, it is overwritten.
If the dimensions of the MATLAB matrix are larger than that of the specified cells, the data overflows into additional rows and columns.
edat must not include the cell
that contains the
MLGetMatrix function. In other
words, be careful not to overwrite the function itself. Also make
sure there is enough room in the worksheet to write the matrix contents.
If there is insufficient room, the function generates a fatal error.
MLGetMatrix function does not automatically
adjust cell addresses. If
edat is an explicit cell
address, edit it to correct the address when you do either of the
Insert or delete rows or columns.
Move or copy the function to another cell.
If worksheet calculation mode is automatic,
when you enter the formula in a cell. If worksheet calculation mode
is manual, enter the
MLGetMatrix function in a
cell, and then press F9 to execute it. However,
pressing F9 in this situation may also execute
other worksheet functions again and generate unpredictable results.
If you use
MLGetMatrix in a macro
MatlabRequest on the line after
internal Spreadsheet Link™ variables and enables
function in a subroutine. Do not include
a macro function unless the function is called from a subroutine.
To work with VBA code in Excel with Spreadsheet Link, you must enable Spreadsheet Link as a reference in the Microsoft® Visual Basic® Editor. For details, see Installation.