MATLAB: Connect via COM
The following steps outline how you can connect STK and MATLAB via COM.
- Establish a connection between MATLAB and STK:
- Option 1: If STK is not running yet, start STK:
uiApplication = actxserver('STK.Application'); uiApplication.Visible = true;
- Option 2: If STK is already running, connect to it:
uiApplication = actxGetRunningServer('STK.Application');
- Option 1: If STK is not running yet, start STK:
- Get the root object:
root = uiApplication.personality2;
- At the end, make sure to close STK. This releases the license for others to use.
% AgUiApplication uiApplication: STK Application uiApplication.Quit; clear uiApplication root
Alternative: If you do not need the STK User Interface and want to maximize performance, create an STK/Engine application:
engine = actxserver('STKX13.Application'); engine.NoGraphics = 1; root = actxserver('AgStkObjects13.AgStkObjectRoot'); clear engine root
You can now control STK from MATLAB. You can now use either Connect commands or Object Model commands to communicate to STK, as described below.
Using STK Connect
The following are example commands that use Connect to communicate with STK:
root.ExecuteCommand('New / Scenario MATLABTest'); root.ExecuteCommand('New / */Facility AGI_HQ'); root.ExecuteCommand('SetPosition */Facility/AGI_HQ Geodetic 40.0386 -75.5966 0.0');
Using the STK Object Model
The following are example commands that use the Object Model to communicate with STK:
root.NewScenario('MATLABTest'); agi_HQ = root.CurrentScenario.Children.New('eFacility','AGI_HQ'); agi_HQ.Position.AssignGeodetic(40.0386, -75.5966, 0.0);