Skip to Main Content Skip to Search
Product Documentation

MLPutMatrix - Create or overwrite MATLAB matrix with data from Microsoft Excel worksheet

Syntax

MLPutMatrix(var_name, mdat)
MLPutMatrix var_name, mdat
out = MLPutMatrix(var_name,mdat)

Description

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.

MLPutMatrix var_name, mdat creates or overwrites matrix var_name in MATLAB workspace with specified data in mdat. Use this syntax in a VBA macro.

out = MLPutMatrix(var_name,mdat) lets you catch errors when executing MLPutMatrix in a VBA macro. If MLPutMatrix fails, then out is a string containing error code. Otherwise, out is 0.

Tips

Input Arguments

var_name

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.

mdat

Location of data to copy into var_name.

mdat must be a worksheet cell address or range name. Do not enclose it in quotes.

Output Arguments

out

0 if the command succeeded. Otherwise, a string containing error code.

Examples

Create or Overwrite a Matrix in the MATLAB Workspace

Create or overwrite matrix A in the MATLAB workspace with the data in the worksheet range A1:C3:

MLPutMatrix "A", Range("A1:C3")

Import Data from a Microsoft Excel Worksheet to the MATLAB Workspace Using the putmatrix Toolbar Button

  1. In the Excel worksheet, select the columns and/or rows you want to export to the MATLAB workspace.

  2. 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.

  3. Enter newmatrix for the MATLAB variable name.

  4. Click OK.

Now you can manipulate newmatrix in the MATLAB Command Window.

newmatrix
newmatrix =

     1     2     3
     4     5     6

See Also

MLAppendMatrix | MLGetMatrix

  


Recommended Products

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.

 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS