英文:
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; \
")
我还尝试在MATLAB函数的末尾添加end
,但仍然遇到相同的错误。
如何避免这个错误并在R中设置MATLAB函数?
英文:
I was trying to reproduce the setfunction
example in R.matlab
. My code is
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; \
")
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论