DADiSP Worksheet Functions > Function Categories > ActiveX > Automation Client > MATLAB
Executes a command in MATLAB using ActiveX.
MATLAB("command", transpose, result)
"command" |
- |
A string. The expression in Matlab syntax to evaluate. |
||||
transpose |
- |
Optional. An integer, transpose row series to column series. |
||||
|
|
|
||||
result |
- |
Optional. An integer, result processing. |
||||
|
|
A scalar, series, or string, the result of the command.
matlab("mdata = rand(10)")
Creates a 10x10 matrix of random values named "mdata" in the Matlab workspace.
matlab("rand(10, 3)")
Creates a 10x3 matrix of random values in the Matlab workspace and returns the result to the current Window.
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.
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:
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.