How Do I Connect STK and Matlab?

« Go Back

Information

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

Extend, Automate, and Visualize

You can use STK and MATLAB together to extend or augment the types of analyses 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. With MATLAB, you can use STK's 2D and 3D visualizations to view any geo-referenced or geometric MATLAB data, such as position and attitude information or an antenna gain pattern. You can load large data sets from STK into MATLAB and use its native 2D and 3D plotting capabilities to understand the data and communicate the results. Learn more about how to extend, automate, and 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 determine which method might be right for your use case, refer to these two 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; it 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. You must have a TCP/IP connection to run MATLAB plugins.

To use a MATLAB plugin inside STK, you need to install and use MATLAB Connectors, but only if you want use the AeroToolbox library inside MATLAB or use a 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 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');

To select a specific STK version, use 'STK##.Application', for example 'STK12.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('STKX12.application');
engine.NoGraphics = 1;
root = actxserver('AgStkObjects12.AgStkObjectRoot');
 

You can now control STK from MATLAB. Use either Connect commands or Object Model commands to communicate to STK.
 
Option 1: Use 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: Use 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.
TitleHow Do I Connect STK and Matlab?
URL NameHow-do-I-connect-STK-and-Matlab

Related Files

Ways2Connect2STK.m