Java调用matlab

2022-09-27 08:34:12 浏览数 (1)

mcc

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 <matlabFile.m>

Excel Add-In mcc -W ‘excel:,’ -T link:lib -b <matlabFile.m>

Hadoop Deployable Archive mcc -H -W ‘hadoop:,CONFIG:<configFile.txt>’ <mapperFile.m> <reducerFile.m> <datastoreInfo.mat>

Spark Application mcc -C -W ‘spark:,’ <matlabFile.m>

MATLAB Compiler SDK C Shared Library mcc -W lib: -T link:lib <matlabFile.m>

C Shared Library mcc -W cpplib: -T link:lib <matlabFile.m>

.NET Assembly mcc -W ‘dotnet:,’ -T link:lib <matlabFile.m>

Java Package mcc -W ‘java:,’ -T link:lib <matlabFile.m>

Python Package mcc -W python: -T link:lib <matlabFile.m>

COM Component mcc -W ‘com:’ -T link:lib <matlabFile.m>

MATLAB Production Server Deployable Archive mcc -W CTF: -U <matlabFile.m>

Deployable Archive for Excel Add-In mcc -W mpsxl: -T link:lib <matlabFile.m>

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的例子

matlab函数文件,sumd.m

代码语言:javascript复制
function sd =sumd(a,b,c)
sd=a b c;
end

通过matlab命令行编译

mcc -W ‘java:sumd,sumd’ -T link:lib sumd.m

输出一下文件

java调用matlab

代码语言:javascript复制
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在如下路径中找到

运行结果如下

0 人点赞