Call Matlab return value in Java

Source: Internet
Author: User

When using Matlab functions in Java, MATLAB returns multiple data for use in Java, due to different language syntax. Access to the online information, rummaging together with their own combat, the method is as follows:

such as the MATLAB function returns the value of n variables, which have a single value, one-dimensional array, two-dimensional array and so on.

In Java, use object[] Rs=cmatlab.matlabfun (n, ...); Accepts the returned parameter. Where Rs[k] represents the value of the variable returned by K in the returned list.

If RS[K] is a single value, such as double type. Use the following method to convert to a double value in Java.

Object[] Rs=cmatlab.matlabfun (N,A,B);//n refers to the number of variables returned, a, b for the input parameters, if the numeric type, you can directly enterMwnumericarray mw= (Mwnumericarray) rs[k];//0<=k<n, if you want to take the value of the K return variable in the return list

DoubleDB=MW.getdouble();//if RS[K] is a single numeric valueDouble[] db= (Double[]) (MW.Todoublearray());//if RS[K] is a one-dimensional array of type doubleint[] db= (int[]) (MW.Tointarray());//if RS[K] is a two-dimensional array of int

If you are unsure which one to use, or if you want to use a different type of conversion, you can use the IDE's Code auto-completion feature for smart hints to see the type of MATLAB return list store.

Add code Auto-completion to the IDE to see tutorials:

Eclipse Code hints feature settings

Eclipse Auto-Complete features Easy Setup | | No modification to edit any file

To invoke MATLAB code in Java, see the previous blog post:

Using Ecilpse (Java) to invoke MATLAB code

Call Matlab return value in Java

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.