MATLAB For Beginners: 20-Minute Video Training Course. (Grab The Training Course and The Cheat Sheet for FREE)

       

In the article, you will learn:

  • How to review the block parameters of one block in your model
  • How to review the block parameters of every block in your model

Get the Parameters of a Single Block

If you want to review a Simulink model, you will probably want to access some of the properties of the blocks of your model so that you can write them down somewhere (e.g. in a Word file).

  • Get all block parameters: you can access any field of a Simulink block by using its handle:
    % gcb gives you the path of the block you clicked on 
    pathBlock = gcb;
    % get the handle of the block 
    blockHandle = get_param(pathBlock, 'Handle');
    % get the structure of the desired block with every field 
    block = get(blockHandle)
  • Get a specific block parameter: you can then¬† access the different fields of your block:
    % get the name of your block
    block.Name
    % get the BlockType of your block
    block.BlockType
    % get the parent of your block
    block.Parent
    % get the LinkStatus of your block
    block.LinkStatus

    The variable “block” of this example is a structure in which every field represents one of the parameters of the block that you clicked on.

Review the Parameters of Every Block

To review your model, all you have to do is apply this to every block:

function getModelInfo(model)
 
% find all the paths of the blocks in your model
blocks = find_system(model, 'LookUnderMasks', 'on', ...
'FollowLinks', 'on', 'LoadFullyIfNeeded', 'on', 'Variants', 'allVariants');
for i = 1:numel(blocks)
    % get the handle of the block
    blockHandle = get_param(blocks{i}, 'Handle');
    % get the structure of the desired block with every field
    block = get(blockHandle)
 
    % get the name of your block
    block.Name
    % get the parent of your block
    block.Parent
end
 
return

The function find_system finds every block of your model. The arguments used in the code above are:

  • LookUnderMasks set to on to find blocks in a subsystem with a mask
  • FollowLinks set to on to find blocks inside library blocks
  • LoadFullyIfNeeded set to on to find blocks in subsystems partially loaded
  • Variants set to allVariants to find blocks in subsystem variants


Leave a Reply