DensityData, DensityFunction

Density values for a density plot

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

MATLAB live scripts support most MuPAD functionality, though there are some differences. For more information, see Convert MuPAD Notebooks to MATLAB Live Scripts.

Value Summary

DensityData, DensityFunctionOptionalList of arithmetical expressions

Graphics Primitives

ObjectsDefault Values
plot::Density 

Description

DensityData is a nested list of “density values” visualized by a plot::Density object.

DensityFunction is a symbolic expression or a procedure defining the “density values” of a plot::Density object.

Density objects of type plot::Density can be defined either by discrete density data or by a density function. In the first case, the object has the slot DensityData. In the latter case, the function describing the densities is stored in the slot DensityFunction.

The internal representation of the DensityData entry of a plot::Density object is a list of lists of density values. Also a matrix or a 2-dimensional array of density values can be assigned to this entry: they are converted to a list of lists.

The DensityFunction of a density object can be a symbolic expression, a procedure or a piecewise object.

Assigning a value to the DensityData entry deletes an existing DensityFunction entry and vice versa.

Examples

Example 1

We create a density plot object defined by a density function:

d := plot::Density(sin(x^2 + y^2), x = -2..2, y = -2..2):
plot(d, Scaling = Constrained):

The density function of this object can be accessed via the DensityFunction slot:

d::DensityFunction

We change the density function by assigning a new value to the DensityFunction slot:

d::DensityFunction := exp(-(x^2 + y^2)/2):
plot(d, Scaling = Constrained)

delete d:

Example 2

We create a density plot object defined by discrete density data:

densitydata := [[0.1, 0.2, 0.3],
                [0.4, 0.5, 0.6]]:
d := plot::Density(densitydata, x = 0..3, y = 0..2):
plot(d):

The density data of the density object can be accessed via the DensityData slot:

densitydata := d::DensityData

The list of list of density values is turned into a matrix. After changing one entry, the new density values are written back into the density object:

densitydata := matrix(densitydata):
densitydata[2, 3] := 0.2:
densitydata

d::DensityData := densitydata:
plot(d)

Although the density values were assigned as a matrix, they are internally stored as a list of lists:

d::DensityData

delete densitydata, d: