R.matlab 库中的 setFunction 无法正确执行?

  • 本文关键字:执行 setFunction matlab r matlab
  • 更新时间 :
  • 英文 :

code1 <- c(
"function [y]=func(x)",
"fprintf('its working! n');",
"y=x;",
"end"
)
x<-10
setFunction(matlab,code1)
evaluate(matlab,"[y] = func(x);")
z <- getVariable(matlab,c("y"))

错误:throw.default中出错("MatlabException:",lasterr(:MatlabException:无法计算表达式"[y]=func(x(;">

R版本:4.0.5

Matlab:R2021a 版本

这在没有返回错误的sprintf的情况下工作:

library(R.matlab)
# Start server
Matlab$startServer(port = 9997)
# Connect to server
matlab <- Matlab(port = 9997); 
code <- "function [y]=func(x) 
y=x;
end"
x <- 10
setVariable(matlab, x = x)
setFunction(matlab,code)
evaluate(matlab,"y=func(x);")
y <- getVariable(matlab,c("y"))
y
# $y
# [,1]
# [1,]    10
# 
# attr(,"header")
# attr(,"header")$description
# [1] "MATLAB 5.0 MAT-file, Platform: PCWIN64, Created on: Fri Jun 11 22:30:39 2021                                        "
# 
# attr(,"header")$version
# [1] "5"
# 
# attr(,"header")$endian
# [1] "little"

相关内容

  • 没有找到相关文章

最新更新