How do I connect STK and Matlab?

Information

 
QuestionHow do I connect STK and Matlab?
Answer
You can integrate STK and MATLAB to automate, extend, or visualize your analysis.

Extend, Automate, or Visualize

You can use STK and MATLAB together to extend or augment the types of analysis that you can perform with only one of them alone. You can operate STK through MATLAB or vice versa to access the capabilities of both tools without needing to switch between application sessions. MATLAB users can use STK's 2D and 3D visualizations to view any geo-referenced or geometric MATLAB data, such as position or attitude information or an antenna gain pattern. Large data sets from STK can be loaded into MATLAB, where you can use its native 2D and 3D plotting capabilities to understand the data and communicate the results. You can learn more about how to extend, automate, or visualize using STK and MATLAB at: STK Help > Integrating with STK > MATLAB Interface

What level of integration between STK and MATLAB are you using?

There are many ways to integrate STK and MATLAB and each method has its own level of complexity and level of integration. To understand which method might be right for your use case, refer to these 2 images:

Ease of MATLAB integration  MATLAB Integration Layers

As you can see, File Interoperability is the easiest method to get started working with MATLAB and STK that requires the least amount of integration. Next comes using the Connect commands or Object Model commands using the COM interface. When connecting STK and MATLAB programmatically, the COM interface is the preferred method since it is very reliable, works for any combination of STK and MATLAB, and does not require any additional installations. A TCP/IP connection is required if you are running MATLAB plugins.

NOTE: You will need to install and use MATLAB Connectors only if you want to use a MATLAB plugin inside STK, use the AeroToolbox library inside MATLAB, or use TCP/IP socket connection to send in Connect commands.

Follow the steps below to connect STK and MATLAB via the COM interface. To learn more about using the MATLAB Connectors, refer to: STK Help > Installation > STK Installation Guide> Using a MATLAB Connector to Interface with STK

To connect to via COM.

1) 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');

2) Get the root object 
root = uiApplication.personality2; 
 

If you do not need the STK User Interface and want to maximize performance, create an STK/Engine application: 
engine = actxserver('STKX11.application');
engine.NoGraphics = 1;
root = actxserver('AgStkObjects11.AgStkObjectRoot');
 

You can now control STK from MATLAB. You can now use either Connect commands or Object Model commands to communicate to STK:
 
Option 1: Using STK Connect
root.ExecuteCommand('New / Scenario MATLABTest');
root.ExecuteCommand('New / */Facility AGI_HQ');
root.ExecuteCommand('SetPosition */Facility/AGI_HQ Geodetic 40.0386 -75.5966 0.0');
 
Option 2: Using the STK Object Model
root.NewScenario('MATLABTest');
agi_HQ = root.CurrentScenario.Children.New('eFacility','AGI_HQ'); 
agi_HQ.Position.AssignGeodetic(40.0386, -75.5966, 0.0);

Attached is a sample .m file to show how to use the COM interface to connect MATLAB to STK.

To learn more about integrating STK with MATLAB, please refer to the Integrating STK with MATLAB webinar.
Resource File 1
Resource File 2