Programmatic equivalent to C/C++ Code->Generate S Function
4 次查看(过去 30 天)
显示 更早的评论
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!
0 个评论
回答(1 个)
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
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!