Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

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 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 concattenated 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

Read and Write MAT Files and Call MATLAB from Within R

v3.6.2
LGPL (>= 2.1)
Authors
Henrik Bengtsson [aut, cre, cph], Andy Jacobson [ctb] (Internal MAT v4 reader), Jason Riedy [ctb] (Support for reading compressed files, sparse matrices and UTF-encoded strings.)
Initial release
2018-09-26

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.