Programmatic equivalent to C/C++ Code->Generate S Function

4 ビュー (過去 30 日間)
Grant Wright
Grant Wright 2023 年 6 月 13 日
回答済み: Vandit 2023 年 6 月 27 日
I am trying to compile library blocks into s-functions as a method of protecting IP in a library. If I right click and select C/C++ Code->Generate S Function, it produces exactly what I want, but there are many blocks to do, so I am trying to do the equivalent programatically.
I have found all of the subsystems to be converted, and passed those to slbuild, but it gives an error:
"Error using coder.build.internal.buildSubsystem. Each model must have 1 target block."
Is there an equivalent command to the Generate S Function gui command? Thanks!

回答 (1 件)

Vandit
Vandit 2023 年 6 月 27 日
Hi,
Once you have identified the subsystems you want to convert into S-Functions, you can iterate through each subsystem and use the 'slbuild' function to generate the S-Function for that subsystem. But before using 'slbuild', you have to check if the top-level model (the model you want to build) has multiple target blocks.
You can refer to the below code in order to implement above steps :
topModel = 'YourModel'; % Replace 'YourModel' with the name of your actual top-level model
targetBlocks = find_system(topModel, 'SearchDepth', 1, 'BlockType', 'Terminator');
if numel(targetBlocks) > 1
disp(['Model: ' topModel ' has multiple target blocks.']);
else
subsystems = find_system(topModel, 'SearchDepth', 1, 'BlockType', 'SubSystem');
for i = 1:numel(subsystems)
currentSubsystem = subsystems{i};
try
slbuild(currentSubsystem);
catch exception
disp(exception.message);
end
end
end
If your top-level model has multiple target blocks, you will need to handle it accordingly. You can either remove the extra target blocks or select one specific block to be the target block.
To know more about 'slbuild'you may refer to the below link:
Hope this helps.
Thankyou

カテゴリ

Help Center および File ExchangeSimulink Coder についてさらに検索

タグ

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by