java调用matlab需要,mcc编译器的参与,mcc命令参数如下
mcc Compile MATLAB functions for deployment outside MATLAB.
mcc [-options] fun [fun2…]
mcc Compile MATLAB functions for deployment outside MATLAB.
Options applicable across all deployment targets:
-? Display help for the mcc command
-a Add additional files or directories to be included in the build
-d Build output directory
-g Include debugging symbol information
-I Add a directory to be searched for MATLAB files
-v Verbose display of build
MATLAB Compiler
Standalone Application (MATLAB|Hadoop|Spark)
mcc -m
Excel Add-In
mcc -W ‘excel:,’ -T link:lib -b
Hadoop Deployable Archive
mcc -H -W ‘hadoop:,CONFIG:
Spark Application
mcc -C -W ‘spark:,’
MATLAB Compiler SDK
C Shared Library
mcc -W lib: -T link:lib
C++ Shared Library
mcc -W cpplib: -T link:lib
.NET Assembly
mcc -W ‘dotnet:,’ -T link:lib
Java Package
mcc -W ‘java:,’ -T link:lib
Python Package
mcc -W python: -T link:lib
COM Component
mcc -W ‘com:’ -T link:lib
MATLAB Production Server
Deployable Archive
mcc -W CTF: -U
Deployable Archive for Excel Add-In
mcc -W mpsxl: -T link:lib
Replace any single quotes (’ ') in the above syntax with double quotes (" ") when executing the mcc command from a Windows Command Prompt.
For more details, execute “doc mcc” from MATLAB.
mcc可以把m文件打包exe或者dll,也可以把m文件(包含m文件调用cpp文件)打包成exe
打包的m文件函数,可以直接传参数运行,类似main函数
matlab函数文件,sumd.m
function sd =sumd(a,b,c)
sd=a+b+c;
end
通过matlab命令行编译
mcc -W ‘java:sumd,sumd’ -T link:lib sumd.m
输出一下文件
package htck;
import java.io.UnsupportedEncodingException;
import sumd.sumd;
public class sumd_test {
public static void main(String[] args) throws UnsupportedEncodingException {
try {
sumd obj = new sumd();
Object[] result = obj.sumd(1,1, 2,3);
System.out.println(result[0]);
obj.sumd(result,new Object[]{1,2,3});
System.out.println(result[0]);
}catch (Exception e){
e.printStackTrace();
}
}
}
需要引用的jar包,javabuilder.jar在如下路径中找到
运行结果如下