Documentation

# setVar

Assign variable in MuPAD notebook

MuPAD® notebooks will be removed in a future release. Use MATLAB® live scripts instead.

To convert a MuPAD notebook file to a MATLAB live script file, see `convertMuPADNotebook`. MATLAB live scripts support most MuPAD functionality, although there are some differences. For more information, see Convert MuPAD Notebooks to MATLAB Live Scripts.

## Syntax

``setVar(nb,MATLABvar)``
``setVar(nb,'MuPADvar',MATLABexpr)``

## Description

````setVar(nb,MATLABvar)` copies the symbolic variable `MATLABvar` and its value in the MATLAB workspace to the variable `MATLABvar` in the MuPAD notebook `nb`.```

example

````setVar(nb,'MuPADvar',MATLABexpr)` assigns the symbolic expression `MATLABexpr` in the MATLAB workspace to the variable `MuPADvar` in the MuPAD notebook `nb`.```

## Examples

collapse all

Copy a variable `y` with a value `exp(-x)` assigned to it from the MATLAB workspace to a MuPAD notebook. Do all three steps in the MATLAB Command Window.

Create the symbolic variable `x` and assign the expression `exp(-x)` to `y`:

```syms x y = exp(-x);```

Create a new MuPAD notebook and specify a handle `mpnb` to that notebook:

`mpnb = mupad;`

Copy the variable `y` and its value `exp(-x)` to the MuPAD notebook `mpnb`:

```setVar(mpnb,'y',y) ```

After executing this statement, the MuPAD engine associated with the `mpnb` notebook contains the variable `y`, with its value `exp(-x)`.

Working in the MATLAB Command Window, assign an expression `t^2 + 1` to a variable `g` in a MuPAD notebook. Do all three steps in the MATLAB Command Window.

Create the symbolic variable `t`:

`syms t`

Create a new MuPAD notebook and specify a handle `mpnb` to that notebook:

`mpnb = mupad;`

Assign the value `t^2 + 1` to the variable `g` in the MuPAD notebook `mpnb`:

`setVar(mpnb,'g',t^2 + 1)`

After executing this statement, the MuPAD engine associated with the `mpnb` notebook contains the variable `g`, with its value ```t^2 + 1```.

## Input Arguments

collapse all

Pointer to a MuPAD notebook, specified as a MuPAD notebook handle or a vector of handles. You create the notebook handle when opening a notebook with the `mupad` or `openmn` function.

Variable in a MuPAD notebook, specified as a variable.

Variable in the MATLAB workspace, specified as a symbolic variable.

Expression in the MATLAB workspace, specified as a symbolic expression.

## See Also

#### Mathematical Modeling with Symbolic Math Toolbox

Get examples and videos