R.matlab 无法设置 MATLAB 函数

huangapple go评论68阅读模式
英文:

R.matlab cannot set MATLAB function

问题

我试图在R.matlab中复制setfunction示例。我的代码是

library(R.matlab)
Matlab$startServer()
matlab <- Matlab()
isOpen <- open(matlab)

setFunction(matlab, " \
  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/B; \
")

我遇到了错误:
R.matlab 无法设置 MATLAB 函数

我还尝试在MATLAB函数的末尾添加end,但仍然遇到相同的错误。

如何避免这个错误并在R中设置MATLAB函数?

英文:

I was trying to reproduce the setfunction example in R.matlab. My code is

library(R.matlab)
Matlab$startServer()
matlab &lt;- Matlab()
isOpen &lt;- open(matlab)

setFunction(matlab, &quot; \
  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/B; \
&quot;)

I encountered the error:
R.matlab 无法设置 MATLAB 函数

I also tried adding an end at the end of the MATLAB function, but still had the same error.

How can I avoid the error and set the MATLAB function within R?

答案1

得分: 1

请删除等号=周围的两个空格,以便第一行变成:

function [win, aver]=dice(B) \

这对我有效。

英文:

Please remove the two white spaces around the equality sign = so that the first line becomes:

function [win, aver]=dice(B) \

This worked for me.

huangapple
  • 本文由 发表于 2023年2月10日 10:53:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/75406482.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定