2017-03-07 46 views
2

Iam新增MATLAB,并希望在Java中使用一些MATLAB脚本。 我试过this来自MATLAB的教程。 我的MATLAB的功能,我想在Java中使用:MATLAB to Java with MATLAB compiler

function y = makesqr(x) 

    y = magic(x); 

此MATLAB脚本应该被打包成Java包。 但创建二进制文件失败后出现错误。 另外我可能没有完全理解它应该工作的方式。 我可以将MATLAB脚本编译为Java,并且Java包可以在Java代码中运行?

荫使用的是Windows 64位与Java版本

1.8.0_121-b13 

Matlab具有

1.7.0_60-b19 


Loading source files for package makesqr... 
Constructing Javadoc information... 
Standard Doclet version 1.8.0_121 
Building tree for all the packages and classes... 
Generating C:\Users\Documents\MATLAB\makesqr\for_testing\doc\html\makesqr\Class1.html... 
C:\Users\Documents\MATLAB\makesqr\for_testing\makesqr\Class1.java:109: warning: no @param for args 
    public static void main (String[] args) 
        ^
C:\Users\Documents\MATLAB\makesqr\for_testing\makesqr\Class1.java:59: warning: no @throws for com.mathworks.toolbox.javabuilder.MWException 
    public Class1() throws MWException 
     ^
C:\Users\Documents\MATLAB\makesqr\for_testing\makesqr\Class1.java:88: warning: no @throws for com.mathworks.toolbox.javabuilder.MWException 
    public Class1(MWComponentOptions componentOptions) throws MWException 
     ^
C:\Users\Documents\MATLAB\makesqr\for_testing\makesqr\Class1.java:77: warning: no @throws for com.mathworks.toolbox.javabuilder.MWException 
    public Class1(String pathToComponent) throws MWException 
     ^
Generating C:\Users\Documents\MATLAB\makesqr\for_testing\doc\html\makesqr\Class1Remote.html... 
C:\Users\Documents\MATLAB\makesqr\for_testing\makesqr\Class1Remote.java:58: error: reference not found 
    * @throws java.jmi.RemoteException An error has occurred during the function call or 
    ^
C:\Users\Documents\MATLAB\makesqr\for_testing\makesqr\Class1Remote.java:61: warning: no @throws for java.rmi.RemoteException 
    public Object[] makesqr(int nargout, Object... rhs) throws RemoteException; 
        ^
C:\Users\Documents\MATLAB\makesqr\for_testing\makesqr\Class1Remote.java:64: warning: no @throws for java.rmi.RemoteException 
    void dispose() throws RemoteException; 
     ^
Generating C:\Users\Documents\MATLAB\makesqr\for_testing\doc\html\makesqr\MakesqrMCRFactory.html... 
Generating C:\Users\Documents\MATLAB\makesqr\for_testing\doc\html\makesqr\package-frame.html... 
Generating C:\Users\Documents\MATLAB\makesqr\for_testing\doc\html\makesqr\package-summary.html... 
C:\Users\Documents\MATLAB\makesqr\for_testing\makesqr\package-info.java:8: warning: empty 
tag 
* 


^
C:\Users\Documents\MATLAB\makesqr\for_testing\makesqr\package-info.java:15: error: unexpected end tag: 


* 

^
C:\Users\Documents\MATLAB\makesqr\for_testing\makesqr\package-info.java:20: warning: empty 
tag 
* 


^
C:\Users\Documents\MATLAB\makesqr\for_testing\makesqr\package-info.java:26: error: unexpected end tag: 


* 

^
Generating C:\Users\Documents\MATLAB\makesqr\for_testing\doc\html\makesqr\package-tree.html... 
Generating C:\Users\Documents\MATLAB\makesqr\for_testing\doc\html\constant-values.html... 
Building index for all the packages and classes... 
Generating C:\Users\Documents\MATLAB\makesqr\for_testing\doc\html\overview-tree.html... 
Generating C:\Users\Documents\MATLAB\makesqr\for_testing\doc\html\index-all.html... 
Generating C:\Users\Documents\MATLAB\makesqr\for_testing\doc\html\deprecated-list.html... 
Building index for all classes... 
Generating C:\Users\Documents\MATLAB\makesqr\for_testing\doc\html\allclasses-frame.html... 
Generating C:\Users\Documents\MATLAB\makesqr\for_testing\doc\html\allclasses-noframe.html... 
Generating C:\Users\Documents\MATLAB\makesqr\for_testing\doc\html\index.html... 
Generating C:\Users\Documents\MATLAB\makesqr\for_testing\doc\html\help-doc.html... 
3 errors 
8 warnings 
Error: An error occurred while shelling out to javadoc (error code = 1). 
Unable to build executable. For more information, pass the -v option to mcc. 
+0

我正在经历完全相同的问题。你到目前为止设法解决它? – palvarez89

回答

1

我的解决方案是使用Java JDK 7,而不是Java的8 Matlab的不支持Java 8

安装Java JDK并设置JAVA_HOME路径。 Here是一个很好的描述

0

为了能够使用MATLAB编译器将MATLAB文件打包到Java库中,必须安装和配置MATLAB使用的相同版本的JDK。 Java版本是MATLAB安装使用,可以通过运行以下命令MATLAB获得:

version -java 

此外,JAVA_HOME环境变量必须正确设置。 Configure Your Java Environment页面包含更多信息。