Export BUSES objects to a .mat file programmatically

18 ビュー (過去 30 日間)
Juan de la Torre
Juan de la Torre 2021 年 10 月 21 日
回答済み: Meet 2024 年 11 月 11 日 6:47
I have multiple bus object in my Matlab workspace and non-virtual buses in working in SImulink.
If I use the Bus Editor I am able to export all of the buses I have in the workspace into a .mat file.
Anyone knows the way of doing this programmatically?
Thanks in advance

回答 (1 件)

Meet
Meet 2024 年 11 月 11 日 6:47
Hi Juan,
You can export bus objects programmatically in MATLAB by using a script to save them into a '.mat' file. Here is a simple approach:
  1. List all variables using the "who" function.
  2. Identify bus objects with "isa(var, 'Simulink.Bus')".
  3. Save the bus objects using the "save" function.
% List variables in the workspace
allVars = who;
% Var for storing Bus objects
busObjects = {};
% Identify bus objects
for i = 1:length(allVars)
var = evalin('base', allVars{i});
if isa(var, 'Simulink.Bus')
busObjects{end+1} = allVars{i};
end
end
% Save bus objects to a .mat file
if ~isempty(busObjects)
save('bus_objects.mat', busObjects{:});
You can refer to the documentation links below for more information:
Hope this helps!!

カテゴリ

Help Center および File ExchangeComposite Interfaces についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by