How can I count the number of non virtual blocks in my model?

조회 수: 9 (최근 30일)
Donald
Donald 2025년 1월 31일
편집: Pramil 2025년 2월 3일
I have a home license

채택된 답변

Pramil
Pramil 2025년 2월 3일
편집: Pramil 2025년 2월 3일
Hi Donald,
To count number of "Nonvirtual" blocks within a model, you can leverage the "find_system" function and its options through the following steps:
1. Get the list of model references within the model:
mdlRefs = find_mdlrefs('Your_Model_Name');
2. Load all the models within the list and run the following command for each model (change the index and model name for each run):
nvBlockCount(1) = length(find_system(mdlRefs{1}, 'LookUnderMasks', 'on', 'FollowLinks', 'on', 'Virtual', 'off'));
3. Sum the count provided from each model to get the total number of "Nonvirtual" blocks:
totalNVBlockCount = sum(nvBlockCount);
Note that you can also use the "cellfun" command as an alternative to Steps 2 and 3 to simplify this workflow:
totalNVBlockCount = sum(cellfun(@(mdlName) length(find_system(mdlName, 'LookUnderMasks', 'on', 'FollowLinks', 'on','Virtual', 'off')), mdlRefs));
You can find the documentation for "find_system" and "find_mdlrefs" for your reference in the following links:
Hope it helps.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Simulink에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by