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"