| Spreadsheet Link™ EX | ![]() |
Worksheet: | MLPutMatrix(var_name, mdat) |
Macro: | MLPutMatrix var_name, mdat |
var_name | Name of MATLAB matrix to create or overwrite. "var_name" (in quotation marks) directly specifies the matrix name. var_name (without quotation marks) is an indirect reference: the function evaluates the contents of var_name to get the matrix name, and var_name must be a worksheet cell address or range name. |
Location of data to copy into var_name. mdat (no quotation marks). Must be a worksheet cell address or range name. |
Creates or overwrites matrix var_name in MATLAB workspace with specified data in mdat. Creates var_name if it does not exist. If var_name exists, this function replaces the contents with mdat. Empty numeric data cells within the range of mdat become numeric zeros within the MATLAB matrix identified by var_name.
If any element of mdat contains string data, mdat is exported as a MATLAB cell array. Empty string elements within the range of mdat become NaNs within the MATLAB cell array.
When using MLPutMatrix in a subroutine, indicate the source of the worksheet data using the Microsoft Excel macro Range. For example:
Sub test()
MLPutMatrix "a", Range("A1:A3")
End Sub
If you have a named range in your worksheet, you can specify the name instead of the range; for example:
Sub test()
MLPutMatrix "a", Range("temp")
End Sub
where temp is a named range in your worksheet.
Create or overwrite matrix A in the MATLAB workspace with the data in the worksheet range A1:C3:
MLPutMatrix "A", Range("A1:C3")
Use the putmatrix toolbar button to import data from an Excel® worksheet to the MATLAB workspace:
In the Excel worksheet, select the columns and/or rows you want to export to the MATLAB workspace.

Click the putmatrix button on the Spreadsheet Link™ EX toolbar. A window appears that prompts you to specify the name of the MATLAB variable in which you want to store your data.

Enter newmatrix for the MATLAB variable name.
Click OK.
Now you can manipulate newmatrix in the MATLAB Command Window.
newmatrix
newmatrix =
1 2 3
4 5 6![]() | MLOpen | MLPutVar | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |