使用MatlabEngine
getVariable
或getVariableAsync
方法从MATLAB中获取变量®基本工作空间。确定合适的MATLAB类型到Java的映射®类型,看到Java数据类型转换.
本示例代码使用MATLABcart2sph
函数将笛卡尔坐标转换为球坐标。的getVariable
方法从MATLAB基础工作空间获取返回的球面坐标变量。
进口com.mathworks.engine。*;public class GetPolar {public static void main(String[] args) throws Exception {MatlabEngine eng = MatlabEngine. startmatlab ();eng。Eval ("[az,el,r] = cart2sph(5,7,3);");double az = engl . getvariable ("az"); / /设置变量double el = engl . getvariable ("el");double r = engl . getvariable ("r"); / /指定变量system . out。println("方位角:" + az);system . out。println("Elevation: " + el); System.out.println("Radius " + r); eng.close(); } }