MATLAB

Purpose:

Executes a command in MATLAB using ActiveX.

Syntax:

MATLAB("command", transpose, result)

"command"

-

A string. The expression in Matlab syntax to evaluate.

transpose

-

Optional. An integer, transpose row series to column series.

 

 

0:

do not transpose

1:

transpose 1xN series results to Nx1 series (default)

result

-

Optional. An integer, result processing.

 

 

0:

do not return result

1:

return result if possible (default)

Returns:

A scalar, series, or string, the result of the command.

Example:

matlab("mdata = rand(10)")

 

Creates a 10x10 matrix of random values named "mdata" in the Matlab workspace.

Example:

matlab("rand(10, 3)")

 

Creates a 10x3 matrix of random values in the Matlab workspace and returns the result to the current Window.

Example:

matlab("rand(1, 10)", 0)

 

Creates a 1x10 matrix of random values in the Matlab workspace and returns the result to the current Window.  Because the series is not transposed, the result is returned as a 1x10 matrix.

Remarks:

The MATLAB function attempts to connect to the running instance of the Matlab automation server, otherwise MATLAB starts and connects to a new instance of Matlab. A licensed copy of Matlab 4.0 or higher must be available on the host machine.

 

Not all Matlab commands return meaningful results.

 

Numeric data is transferred as double precision values.

 

The built-in Matlink Module provides a simpler and perhaps more natural "dot" syntax for running Matlab commands and functions. For example

 

matlab("rand(10, 3)")

 

can be invoked as:

 

ml.rand(10, 3)

 

This syntax has the advantage of automatically and transparently passing data to and from Matlab. For example:

 

W1: gnorm(1000, 1)

W2: ml.diff(w1)

 

W1 contains 1000 samples of random data. W2 processes the data in W1 with the Matlab diff function. When W1 changes, W2 automatically updates and the new data is processed by Matlab.

 

The Matlab diff function executes just like any other function except:

 

1.

The required data is sent to Matlab

2.

Matlab executes the diff function on the data

3.

The result is returned to W2

 

 

Matlab functions can be mixed with standard functions. For example:

 

W1: gnorm(1000, 1)

W2: movavg(ml.diff(w1), 10)

 

The Matlab diff function is applied to the data in W1 and the result is smoothed by means of a 10 point moving average computed by the MOVAVG function.

 

Data exchange can also be accomplished:

 

// assign a series to a Matlab variable
ml.MatVar = 1..100;
 
// return a Matlab variable
x = 10 * ml.MatVar;

 

Matlab expressions in original Matlab syntax are also evaluated directly via the > prompt.

 

W1: >1:100

 

is equivalent to:

 

W1: matlab("1:100")

 

Multiple return values from Matlab are supported:

 

W1: rand(10)

W2: (v, d) = ml.eig(W1);d

 

The Matlab eig function returns two arrays. The second array, a diagonal matrix of eigenvalues, is placed and displayed in W2.

 

Error messages or warnings produced by Matlab are displayed. Functions that produce textual results are presented in a pop-up dialog box. For example, to display a list of currently available Matlab variables with corresponding data types:

 

ml.whos

 

The MLHELP and MLDOC functions display Matlab online documentation. For example:

 

mldoc magic

 

displays the documentation for the Matlab magic function.

 

By default, the Matlab ActiveX server is hidden.

 

mlshow(1)

 

displays the Matlab automation server interface.

See Also:

CREATEOBJECT

EVAL

EVALTOSTR

EXECUTE

FEVAL