from
Simulink Model Reference Total Block Count
by Robyn Jackey
Calculate the total block count for a Simulink model, including those in model references.
|
| CountBlocks_mdlRef(ModelName)
|
function NumBlks = CountBlocks_mdlRef(ModelName)
% CountBlocks_mdlRef - Count complete model block total
% -------------------------------------------------------------------------
% Abstract: This function computes the raw block total for the specified
% model, looking within masked subsystems, library links, and
% model references.
%
% Syntax:
% NumBlks = CountBlocks_mdlRef(ModelName)
%
% Inputs:
% ModelName - Name of the top model
%
% Outputs:
% NumBlks - Block count total
%
% Examples:
% totalblocks = CountBlocks_mdlRef('sldemo_mdlref_basic')
%
% Notes:
% All reference models and libraries must exist on the MATLAB
% path, and must not error when loaded.
%
% Copyright 2008 - 2009 The MathWorks, Inc.
%
% Auth/Revision:
% The MathWorks Consulting Group
% $Author: $
% $Revision: $ $Date: $
% -------------------------------------------------------------------------
% Load the model silently
load_system(ModelName);
% Count the blocks in this model
NumBlks = numel(find_system(ModelName,'FollowLinks','on','LookUnderMasks','all'));
% Find all the model reference blocks
ModelNameRefBlks = find_system(ModelName,'FollowLinks','on','LookUnderMasks','all',...
'BlockType','ModelReference');
% Get all the referenced model names
RefModels = get_param(ModelNameRefBlks,'ModelName');
% Now get a unique list of models, and the number of instances of each
[UniqueModels, tmp, UniqueModelsLoc] = unique(RefModels);
% Loop through each model and count blocks
% Multiply by the number of instances of each reference model]
for i=1:numel(UniqueModels)
NumInstances = sum(UniqueModelsLoc==i);
NumBlks = NumBlks + (NumInstances * CountBlocks_mdlRef(UniqueModels{i}));
end
|
|
Contact us at files@mathworks.com