setFunction.Matlab: Defines a MATLAB function

setFunction.MatlabR Documentation

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 class 'Matlab'
setFunction(this, code, name=NULL, collapse="\n", ...)

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.

Value

Returns nothing.

Author(s)

Henrik Bengtsson

See Also

For more information see Matlab.

Examples

## Not run: 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)

## End(Not run)

R.matlab documentation built on Aug. 26, 2022, 1:07 a.m.