Documentation Center

  • Trial Software
  • Product Updates

MLAppendMatrix

Create or append MATLAB matrix with data from Microsoft Excel worksheet

Syntax

MLAppendMatrix(var_name,mdat)
MLAppendMatrix var_name,mdat
out = MLAppendMatrix(var_name,mdat)

Description

MLAppendMatrix(var_name,mdat) appends data in mdat to MATLAB® matrix var_name or creates var_name if it does not exist. Use this syntax when working directly in a worksheet.

MLAppendMatrix var_name,mdat appends data in mdat to MATLAB matrix var_name or creates var_name if it does not exist. Use this syntax in a VBA macro.

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

Input Arguments

var_name

Name of MATLAB matrix to which to append data.

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. Do not use the MATLAB variable ans as var_name.

mdat

Location of data to append to var_name.

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

mdat must contain either numeric data or string data. Data types cannot be combined within the range specified in mdat. Empty mdat cells become MATLAB matrix elements containing zero if the data is numeric, and empty strings if the data is a string.

Output Arguments

out

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

Examples

expand all

Append Data from a Worksheet Cell Range to a MATLAB Matrix

In this example, B is a 2-by-2 MATLAB matrix. Append the data in worksheet cell range A1:A2 to B:

MLAppendMatrix("B", A1:A2)
  

A1

  

A2

B is now a 2-by-3 matrix with the data from A1:A2 in the third column.

Append Data from a Named Worksheet Cell Range to a MATLAB Matrix

B is a 2-by-2 MATLAB matrix. Cell C1 contains the label (string) B, and new_data is the name of the cell range A1:B2. Append the data in cell range A1:B2 to B:

MLAppendMatrix(C1, new_data)
  
  

A1

B1

A2

B2

B is now a 4-by-2 matrix with the data from A1:B2 in the last two rows.

More About

expand all

Tips

  • MLAppendMatrix checks the dimensions of var_name and mdat to determine how to append mdat to var_name. If the dimensions allow appending mdat as either new rows or new columns, it appends mdat to var_name as new rows. If the dimensions do not match, the function returns an error.

  • If mdat is not initially an Excel® Range data type and you call the function from a worksheet, MLAppendMatrix performs the necessary type coercion.

  • If mdat is not an Excel Range data type and you call the function from within a Microsoft® Visual Basic® macro, the call fails. The error message ByRef Argument Type Mismatch appears.

See Also

Was this topic helpful?