首页 > 后端开发 > 正文

java调用matlab有哪些方法

2024-05-14 00:16:10 | 我爱编程网

最近经常有小伙伴私信询问java调用matlab有哪些方法相关的问题,今天,我爱编程网小编整理了以下内容,希望可以对大家有所帮助。

本文目录一览:

java调用matlab有哪些方法

java调用matlab有哪些方法

在Java中调用Matlab的方法时,有三种方式。大致都有2个参数,第一个参数是定义输出结果,第二个参数为输入参数。

方式一:functionName(int arg0, Object... agr1): Object[]

方式二:functionName(List arg0, List agr1): void

方式三:functionName(Object[] arg0, Object[] agr1): void

java调用matlab有哪些方法

如何在Java中调用Matlab?

一、matlab版本必须支持java

在command 模式下面运行deploytool,如果支持该命令即可使用

二、matlab中function的书写

%定义一个函数operation(a,b),求a与b的加减乘除运算,并返回结果

%函数定义function 输出变量列表[s,m,...] 函数名(输入变量列表)sum,sub,mul,div中

function [sum,sub,mul,div] = operation(a,b);

sum = a + b;

sub = a - b;

mul = a * b;

div = a / b;

end

PS:上面function后中括号部分与java中调用该operation的返回值有关系,在java中调用的 Object result[] = XXX.operation(4,a,b); 4表示有4个返回值,分别存放在result[0]到result[4]中。

三、使用matlab编译生成jar

在matlab命令窗口下输入 deploytool,就会弹出一个编译窗口,

然后点击,file,选择new-deployment project,

然后选择matlab builder jave。

name的地方填写工程名,

ocation填写该工程的存储位置。

点击ok。

然后,把m文件添加到工程中,先new一个class,这个class的名字就是你将来在java中需要new的class的名字,也就是matlab中operation所在的class名字然后将你的m文件添加到这个class目录下,然后直接build即可。

四、在java中使用matlab的函数我爱编程网

现在eclipse下面new一个新的java工程,然后将第三部build成功后产生的文件夹下面的distrib目录中的XXX.jar 以及你matlab安装目录下/toolbox/javabuilder/jar/javabuilder.jar加入你的java工程extend lib 中去。

然后你可以清晰的看到XXX.jar中包含的函数和类

五、可能碰到的问题

Exception in thread "main" java.lang.UnsatisfiedLinkError: Failed to find the library libmwmclmcrrt.so.7.13, required by MATLAB Builder JA, on java.library.path.

This library is typically installed along with MATLAB or the MCR, its absence may indicate an issue with that installation or the current path configuration.

The MCR version that this component is trying to use is: 7.13.

Failed to find the library mclmcrrt710.dll,required by MATLAB Builder JA, on java.library.path

原因是2009a要对应安装mclmcrrt7.10。在MATLAB安装目录下查找:\toolbox\compiler\deploy\win32,找到MCRInstaller.exe 安装,重启Eclipse即可。

资料来源:

_stu_zhang/article/details/7605391

java调用matlab有哪些方法

java调用matlab

我爱编程网(https://www.52biancheng.com)小编还为大家带来java调用matlab的相关内容。

我分别百度了那两个问题,解决方案好像是一样的。

把你的matlab的bin的路径添加到系统的path路径中,也可以把你的mcr的bin路径添加到path中,你可以采用命令行的形式:

set Path=%Path%;\bin\win32

或者

set Path=%Path%;\\runtime\win32,

参考网址:

-78FIKN/index.html?product=MJ&solution=1-78FIKN

_thread/296636

原文是:

You are receiving this error because the required "bin" directories of either the MATLAB or MATLAB Compiler Runtime (MCR) installations have not been set up correctly on your Windows machine's PATH environment variable. You can make the necessary runtime libraries visible to MATLAB-compiled components by adding either:

\bin\win32   or     \\runtime\win32

to your system PATH, depending on whether you are developing against a local MATLAB installation, or the MCR. Either replace  with the MATLAB installation directory on your machine (e.g., C:\Program Files\MATLAB\R2008a), or  with the MCR installation directory (e.g., C:\Program Files\MATLAB\MATLAB Compiler Runtime) and  with the version of the installed MCR (e.g., v78).

以上就是我爱编程网小编整理的内容,想要了解更多相关资讯内容敬请关注我爱编程网。更多相关文章关注我爱编程网:www.52biancheng.com

免责声明:文章内容来自网络,如有侵权请及时联系删除。
与“java调用matlab有哪些方法”相关推荐