• 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在如下路径中找到
    在这里插入图片描述
    运行结果如下
    在这里插入图片描述

  • 相关阅读:
    js中的原型链
    直播带货代运营公司9人被抓
    LVS负载均衡-TUN模式(模拟不同网段)
    Java中的StringTable常量池
    关于 React 性能优化和数栈产品中的实践
    面向对象设计与分析(41)建造者模式builder
    sql update 不更新
    Zookeeper - Java API 对节点操作
    【PyTorch】如何取得预训练模型的标签label列表(以 Alexnet 在 ImageNet 上的预训练模型为例)
    SwiftUI 4.0为Toggle视图在iOS 16中增加属性多选功能
  • 原文地址:https://blog.csdn.net/daoer_sofu/article/details/126698908