How to count the number of integrations from Integrator blocks in a Simulink model in R2020a?

8 visualizzazioni (ultimi 30 giorni)
How to count the number of integrations from Integrator blocks in a Simulink model in R2020a?
I use Integrator blocks in Simulink and feed them with multi-dimensional signals, so I want to count how many "integrations" are done within the Integrator block.

Risposta accettata

MathWorks Support Team
MathWorks Support Team il 2 Set 2021
Modificato: MathWorks Support Team il 7 Ott 2021
The (maybe) easiest way to do this is the following:
You can use the following 'Simulink.findBlocksofType' API and search for all Integrator blocks in the model and it's children:
By specifying options using 'Simulink.FindOptions' you can customize the search:
If you only need the number of Integrator blocks, you can then use the 'length' command to get this value (here done for the current system):
>> length(Simulink.findBlocksOfType(gcs,'Integrator'))
But if you want to count the total number, if you maybe have vector signals, which you maybe want to count as separate integration, you can do it for example like the following:
%Initialize some data like system name and count
systemName = gcs;
countInteg = 0;
%%
%Bring the model into compiled state and find integrators and get port
%handles
set_param(systemName,'SimulationCommand', 'start','SimulationCommand', 'pause')
blocks = Simulink.findBlocksOfType(systemName,'Integrator');
ph = get_param(blocks,'PortHandles');
%%
for ii=1:length(ph)
dim = get_param(ph{ii}.Outport,'CompiledPortDimensions'); %extract output dimensions of the Integrator blocks
countInteg = countInteg + prod(dim); %Multiply the dimensions to bring the value to a scalar value
end
set_param(systemName,'SimulationCommand', 'stop') %stop simulation
%%
%Output the result
disp('Number of Integrations are');
countInteg
The scripts works like the following:
It brings the model into the compiled state, then it searches all Integrator blocks and then finally checks how the output dimensions look a like and adds them up, after multiplying the dimensions.If this does not fit to your needs, contact our Technical Support team for further help.

Più risposte (0)

Categorie

Scopri di più su Modeling in Help Center e File Exchange

Prodotti


Release

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by