import com.mathworks.engine.MatlabEngine;
import java.lang.invoke.MethodHandles;
import java.util.concurrent.Future;
public class TestBed
{
public static void main( String arguments[] )
{
Future<MatlabEngine> matlabEngineFuture;
MatlabEngine matlabEngine;
Future<Object> variableFuture;
Future<Void> voidFuture;
try
{
matlabEngineFuture = MatlabEngine.startMatlabAsync();
matlabEngine = matlabEngineFuture.get();
// Experiment 1:
//matlabEngine.eval( "MyStructure1.child( 1, 1 ) = 1;" );
//matlabEngine.eval( "MyStructure1.child( 1, 2 ) = 1;" );
//matlabEngine.eval( "MyStructure1.child( 2, 1 ) = 1;" );
//matlabEngine.eval( "MyStructure1.child( 1, 2 ) = 1;" );
//
//System.out.println( "Before retrieving MyStructure1" );
//
//variableFuture = matlabEngine.getVariableAsync( "MyStructure1" );
//variableFuture.get();
//
//System.out.println( "After retrieving MyStructure1" );
//
//voidFuture = matlabEngine.fevalAsync( 0, "clear", "MyStructure1" );
//System.out.println( "voidFuture = " + voidFuture );
//voidFuture.get();
// Experiment 2:
//matlabEngine.eval( "MyStructure2.child( 1 ).child1 = 1;" );
//matlabEngine.eval( "MyStructure2.child( 2 ).child1 = 1;" );
//
//System.out.println( "Before retrieving MyStructure2" );
//
//variableFuture = matlabEngine.getVariableAsync( "MyStructure2" );
//variableFuture.get();
//
//System.out.println( "After retrieving MyStructure2" );
//
//voidFuture = matlabEngine.fevalAsync( 0, "clear", "MyStructure2" );
//voidFuture.get();
// Experiment 3:
//matlabEngine.eval( "MyStructure3.child1.child1 = 1;" );
//matlabEngine.eval( "MyStructure3.child2.child1 = { 'testString1', 'testString2' };" );
//
//System.out.println( "Before retrieving MyStructure3" );
//
//variableFuture = matlabEngine.getVariableAsync( "MyStructure3" );
//variableFuture.get();
//
//System.out.println( "After retrieving MyStructure3" );
//
//voidFuture = matlabEngine.fevalAsync( 0, "clear", "MyStructure3" );
//voidFuture.get();
// Experiment 4:
matlabEngine.eval( "MyStructure4.child( 1, 1 ).child1 = 1;" );
matlabEngine.eval( "MyStructure4.child( 1, 2 ).child1 = 1;" );
matlabEngine.eval( "MyStructure4.child( 2, 1 ).child1 = 1;" );
matlabEngine.eval( "MyStructure4.child( 1, 2 ).child1 = 1;" );
System.out.println( "Before retrieving MyStructure4 (the JVM crashes here)" );
variableFuture = matlabEngine.getVariableAsync( "MyStructure4" );
variableFuture.get();
System.out.println( "After retrieving MyStructure4 (this is never displayed)" );
voidFuture = matlabEngine.fevalAsync( 0, "clear", "MyStructure4" );
voidFuture.get();
// ----------------------------------------------------------------------------------------
}
catch ( Exception exception )
{
System.out.println( "This is never displayed" );
exception.printStackTrace();
}
System.out.println( "This is never displayed" );
}
}