SelectTreeItem error and MATLAB/CST gain discrepancy (COM interface, CST 2025)

17 views (last 30 days)
Hello,
I am controlling CST Microwave Studio 2025 from MATLAB using the COM Automation interface to automate the simulation of a rectangular patch antenna and automatically extract key results: resonant frequency, S11, axial ratio (AR), and gain at 3.5 GHz.
While extracting S11 works correctly, I encounter issues with gain extraction. I have tried two approaches, each with its own problem:
Method 1 – Exporting Farfield ASCII
I export the Farfield data via COM and compute the gain in MATLAB from the E-field components (Eθ, Eφ, etc.).
Issue: the gain calculated in MATLAB differs from the value displayed in CST (Farfield → 3D Plot → Gain / Total Gain).
Method 2 – Using SelectTreeItem
I attempted to automate the Farfield export directly with the following command:
treeItem = sprintf('Farfields\\Farfield3.5 [1]');
invoke(mws, 'SelectTreeItem', treeItem);
Issue: this command returns the error:
Error using Interface. SelectTreeItem
No input argument
My question
How can I resolve the SelectTreeItem error and automatically retrieve (or calculate in MATLAB) the same “Total Gain” or “Realized Gain” as displayed in CST, without discrepancies?

Answers (1)

dpb
dpb on 8 Nov 2025 at 19:06
Moved: dpb on 8 Nov 2025 at 19:06
This isn't really about MATLAB, but the syntax for the COM interface to the CST application. That will be in the documentation for that product. As a general comment, writing command strings to variables and then passing those is a "'round-the-mulberry-bush" approach; it would be simpler to just write the command syntax for the method from the handle to the proper COM Object. About the only way to debug COM interaction is to set a breakpoint in your code before the failure line and then play around interactively to iron out the syntax issues.
That said, I'd suggest you look at the File Exchange submmission <TCSTInterface>; it may have already solved your problem for you. Caveat: I don't even know what the CST Microwave TB is, so no experience, but the submission appears to be very comprehensive with high marks.
  1 Comment
Umar
Umar on 8 Nov 2025 at 19:57

Hi @Khadijah,

I could be wrong but it seems like the main issue might be with either tree item referencing or unit mismatch in the gain calculation. Based on my experience by listing the available tree items and making sure you’re referencing the correct one, you should be able to fix the SelectTreeItem issue. To debug, you can list all available tree items and verify that you're referencing the correct path for the Farfield data. Use the following MATLAB command to retrieve the tree item names:

treeItems = mws.GetTreeItemNames();  % List all tree items
disp(treeItems);  % Display the tree items to verify the correct path

Once you confirm the correct path, use it directly with SelectTreeItem. For instance, if your tree item path is 'Farfields\\Farfield3.5 [1]', ensure there are no extra spaces or incorrect characters.

Also, remember to account for gain in dB and consider how CST is calculating Total Gain versus Realized Gain.

Hope this helps.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!