Main Content

Java에서 MATLAB 세션 시작하기 및 닫기

Java® 프로그램에서 동기식 또는 비동기식으로 MATLAB® 세션을 시작할 수 있습니다. 다음 MatlabEngine static 메서드를 사용하여 MATLAB을 시작합니다.

  • MatlabEngine.startMatlab — MATLAB 세션을 동기식으로 시작합니다.

  • MatlabEngine.startMatlabAsync — MATLAB 세션을 비동기식으로 시작합니다.

항상 MATLAB Engine 세션 닫기의 메서드 중 하나를 사용하여 MATLAB 세션을 종료해야 합니다.

동기식으로 MATLAB 시작하기

Java에서 MATLAB을 동기식으로 시작합니다.

import  com.mathworks.engine.*;

public class StartMatlab {
    public static void main(String[] args) throws Exception {
        MatlabEngine eng = MatlabEngine.startMatlab();
        ...
        eng.close();
    }
}

비동기식으로 MATLAB 시작하기

Java에서 MATLAB을 비동기식으로 시작합니다. 반환된 Future 객체의 get 메서드를 사용하여 MatlabEngine 객체가 반환될 때까지 기다립니다.

import  com.mathworks.engine.*;
import java.util.concurrent.Future;

public class StartMatlab {
    public static void main(String[] args) throws Exception {
        Future<MatlabEngine> engFuture = MatlabEngine.startMatlabAsync();
        //Do work while MATLAB engine starts
        ...
        MatlabEngine eng = engFuture.get();
        ...
        eng.close();
    }
}

시작 옵션과 함께 엔진 시작하기

MATLAB 세션을 시작할 때 MATLAB 시작 옵션을 지정할 수 있습니다. MATLAB 시작 옵션에 대한 자세한 내용은 일반적으로 사용되는 시작 옵션 항목을 참조하십시오.

MatlabEngine.startMatlab 메서드와 MatlabEngine.startMatlabAsync 메서드는 입력값으로 string형 배열을 받습니다.

MATLAB 시작 옵션을 사용하여 엔진을 동기식으로 시작합니다.

import  com.mathworks.engine.*;

public class StartMatlab {
    String[] options = {"-noFigureWindows", "-r", "cd H:"};
    public static void main(String[] args) throws Exception {
        MatlabEngine eng = MatlabEngine.startMatlab(options);
        ...
        eng.close();
    }
}

MATLAB 시작 옵션을 사용하여 엔진을 비동기식으로 시작합니다.

import  com.mathworks.engine.*;
import java.util.concurrent.Future;

public class StartMatlab {
    public static void main(String[] args) throws Exception {
        String[] options = {"-noFigureWindows", "-r", "cd H:"};
        Future<MatlabEngine> engFuture = MatlabEngine.startMatlabAsync(options);
        ...
        MatlabEngine eng = engFuture.get();
        ...
        eng.close();
    }
}

MATLAB Engine 세션 닫기

MATLAB Engine 세션을 종료하려면 다음 MatlabEngine 메서드 중 하나를 사용하십시오.

메서드용도

close

Java 프로세스가 디폴트 값인 비공유 세션으로 MATLAB 세션을 시작한 경우, close()는 MATLAB을 종료합니다.

MATLAB 세션이 공유 세션인 경우, close()는 이 Java 프로세스에서 MATLAB을 연결 해제합니다. 다른 연결이 없으면 MATLAB이 종료됩니다.

disconnect, disconnectAsync

현재 MATLAB 세션에서 동기식 또는 비동기식으로 연결 해제합니다.

quit, quitAsync

현재 MATLAB 세션을 동기식 또는 비동기식으로 강제 종료합니다.

참고 항목

관련 항목