我使用MatlabConrol连接 Java 和 MATLAB。我想向 MATLAB 发送一个图像路径,以使用匹配的函数对其进行处理,并返回一些相似的图像和路径,以在 Java GUI 中显示。
将图像路径传递给 MATLAB 时,我总是遇到同样的错误:
Error using eval
Undefined function 'getinput' for input arguments of type 'char'.
这是我的 MATLAB 函数:
function matlab = getinput(input)
results = hgr(input);
还有我的 Java 代码:
imag = ImageIO.read(fileChoose.getSelectedFile());
ImagePath = fileChoose.getSelectedFile().getAbsolutePath();
public void SendingMatlabControl() throws MatlabConnectionException,
MatlabInvocationException {
// create proxy
MatlabProxy proxy;
// Create a proxy, which we will use to control MATLAB
MatlabProxyFactory factory = new MatlabProxyFactory();
proxy = factory.getProxy();
// Display 'hello world' like before, but this time using feval
try {
// call builtin function
proxy.eval("getinput('imagepath')");
// call user-defined function (must be on the path)
proxy.eval("addpath('E:\\vm')");
proxy.feval("matlab");
proxy.eval("rmpath('E:\\vm)");
} catch (MatlabInvocationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// Disconnect the proxy from MatLab
proxy.disconnect();
}