Learn R Programming

R.matlab (version 3.7.0)

setFunction.Matlab: Defines a MATLAB function

Description

Creates an M-file on the MATLAB server machine (in the working directory) containing the specified MATLAB function definition.

Usage

# S3 method for Matlab
setFunction(this, code, name=NULL, collapse="\n", ...)

Value

Returns nothing.

Arguments

code

The MATLAB function definition.

name

Optional name of the function, which will defined the name of the M-file where the function is stored. If NULL, the name is extracted from the code.

collapse

The string that the code lines, if there are more than one, is going to be concatenated with.

...

Not used.

Author

Henrik Bengtsson

See Also

For more information see Matlab.

Examples

Run this code
if (FALSE) code <- c(
  "function [win, aver] = dice(B)",
  "%Play the dice game B times",
  "gains = [-1, 2, -3, 4, -5, 6];",
  "plays = unidrnd(6, B, 1);",
  "win = sum(gains(plays));",
  "aver = win;"
)

setFunction(matlab, code)
evaluate(matlab, "[w, a] = dice(1000);")
res <- getVariable(matlab, c("w", "a"))
print(res)

Run the code above in your browser using DataLab