Main Content

MLDeleteMatrix

Delete MATLAB matrix

Description

= MLDeleteMatrix(var_name) deletes the named matrix from the MATLAB® Workspace. Use this syntax when working directly in a worksheet.

example

MLDeleteMatrix var_name deletes the named matrix from the MATLAB Workspace. Use this syntax in a VBA macro.

example

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

Examples

collapse all

Delete a matrix in the MATLAB Workspace using the MLDeleteMatrix function in an Excel® worksheet.

Create a 2-by-2 MATLAB matrix A.

A = [2 3; 4 6];

Open Excel and make sure cell A1 is selected in the worksheet. Delete the matrix A using the MLDeleteMatrix function. Enter this text in the cell and press Enter.

= MLDeleteMatrix("A")

The MLDeleteMatrix function deletes the matrix from the MATLAB Workspace.

Delete a matrix in the MATLAB Workspace using the MLDeleteMatrix function in a VBA macro.

Create a 2-by-2 MATLAB matrix A.

A = [2 3; 4 6];

On the Developer tab in Excel, click Visual Basic in the Code group. The Visual Basic® Editor window opens.

Select Insert > Module to insert a new module. In the Module1 window, enter this VBA code containing a macro named DeleteMatrix.

Sub DeleteMatrix()
    MLDeleteMatrix "A"
End Sub

The DeleteMatrix macro uses the MLDeleteMatrix function to delete the matrix A from the MATLAB Workspace.

For details about working with modules, see Excel Help.

Run the macro by clicking Run Sub/UserForm button on the VBA toolbar. For details about running macros, see Excel Help.

The MLDeleteMatrix function deletes the matrix from the MATLAB Workspace.

Input Arguments

collapse all

Name of the MATLAB matrix to delete, specified as a string.

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.

Example: "A"

Tips

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

Version History

Introduced before R2006a