Create or overwrite MATLAB matrix with data from Microsoft Excel worksheet
MLPutMatrix var_name, mdat
out = MLPutMatrix(var_name,mdat)
MLPutMatrix(var_name, mdat) creates or overwrites matrix var_name in MATLAB® workspace with specified data in mdat. Creates var_name if it does not exist. Use this syntax when working directly in a worksheet.
Name of MATLAB matrix to create or overwrite.
var_name in quotes directly specifies the matrix name. var_name without quotes specifies a worksheet cell address (or range name) that contains the matrix name.
Location of data to copy into var_name.
mdat must be a worksheet cell address or range name. Do not enclose it in quotes.
Create or overwrite matrix A in the MATLAB workspace with the data in the worksheet range A1:C3:
MLPutMatrix "A", Range("A1:C3")
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.
Now you can manipulate newmatrix in the MATLAB Command Window.
newmatrix newmatrix = 1 2 3 4 5 6
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 mdatmdat 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.