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