• Java调用matlab


    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

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

    matlab函数文件,sumd.m

    function sd =sumd(a,b,c)
    sd=a+b+c;
    end
    
    • 1
    • 2
    • 3

    通过matlab命令行编译

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

    输出一下文件
    在这里插入图片描述

    java调用matlab

    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();
            }
        }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19

    需要引用的jar包,javabuilder.jar在如下路径中找到
    在这里插入图片描述
    运行结果如下
    在这里插入图片描述

  • 相关阅读:
    Java中collections类常用方法介绍 (#将指定集合包装成线程同步的集合)
    NOIP2023模拟13联测34 competition
    【C++】C++11部分特性
    安卓机型-MTK芯片掉串码 掉基带 如何用工具进行修复 改写参数
    手写RISC-V处理器--开篇
    git撤回本地的commit或者push到远程的代码
    手写实现简易Spring框架
    部署一个自己的GPT客户端[以ChatGPT-Next-Web为例]
    SpringBoot项目使用hutool工具进行HttpClient接口调用的处理(文件上传)
    Element类型
  • 原文地址:https://blog.csdn.net/daoer_sofu/article/details/126698908