gpt4 book ai didi

java - Java 中的 Matlab 控制

转载 作者:行者123 更新时间:2023-11-30 07:56:35 24 4
gpt4 key购买 nike

我正在开发 https://code.google.com/p/matlabcontrol/wiki/Walkthrough 中的以下程序。我希望使用Matlab控件在Java中调用Matlab函数。我在程序中导入了matlabcontrol。前 2 个示例程序对我来说效果很好。

<小时/>
public static void main(String[] args) throws MatlabConnectionException, MatlabInvocationException
{
//Create a proxy, which we will use to control MATLAB
MatlabProxyFactory factory = new MatlabProxyFactory();
MatlabProxy proxy = factory.getProxy();

//Create a 4x3x2 array filled with random values
proxy.eval("array = randn(4,3,2)");

//Print a value of the array into the MATLAB Command Window
proxy.eval("disp(['entry: ' num2str(array(3, 2, 1))])");

//Get the array from MATLAB
MatlabTypeConverter processor = new MatlabTypeConverter(proxy);
MatlabNumericArray array = processor.getNumericArray("array");

//Print out the same entry, using Java's 0-based indexing
System.out.println("entry: " + array.getRealValue(2, 1, 0));

//Convert to a Java array and print the same value again
double[][][] javaArray = array.getRealArray3D();
System.out.println("entry: " + javaArray[2][1][0]);

//Disconnect the proxy from MATLAB
proxy.disconnect();
}
<小时/>

当我在 Windows 上运行此程序时,Java 给出以下错误:

C:\Program Files\Java\jdk1.6.0_45\bin>javac Helloworld3.java
Helloworld3.java:61: cannot find symbol
symbol : class MatlabTypeConverter
location: class Helloworld3
MatlabTypeConverter processor = new MatlabTypeConverter(proxy);
^
Helloworld3.java:61: cannot find symbol
symbol : class MatlabTypeConverter
location: class Helloworld3
MatlabTypeConverter processor = new MatlabTypeConverter(proxy);
^
Helloworld3.java:62: cannot find symbol
symbol : class MatlabNumericArray
location: class Helloworld3
MatlabNumericArray array = processor.getNumericArray("array");
^
3 errors

如有任何帮助,我们将不胜感激!谢谢。

最佳答案

顺便说一句,我得到了答案。我们需要将文件导入为:

import matlabcontrol.extensions.MatlabTypeConverter;

现在,一切正常!

关于java - Java 中的 Matlab 控制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32588130/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com