The setFunction in R.matlab library isn't executing properly?

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"))

Error: Error in throw.default("MatlabException: ", lasterr) : MatlabException: Failed to evaluate expression '[y] = func(x);'

Version of R: 4.0.5

Version of Matlab: R2021a