## MATLAB Fast Automation: Tired of Working? Here's Your Step-by-Step Action Plan to Automate Your Work With MATLAB.

• When you should use a mask
• How to create and document a mask on a block

## Why Use a Mask ?

Mainly, masks are used to document a particular block to explain what it does. This is particularly useful for library blocks since one of the incentives is saving time by using a block that has already been coded. To do so, it should not be necessary to understand how the block was coded; this is why documenting a block in this way can be very useful.

Adding a mask can also be used to prevent a MATLAB script from entering into a particular block. For example, if you want to apply a script that checks the naming rules related to the parameters of your model, you may want your script not to enter into your mask’s blocks. Using a mask allows you to define parameters locally to a specific block. Thus it could make sense to have different naming rules for a block with a mask since there is no risk of conflict with parameters defined somewhere else in the model.

## Create and Document a Mask

If you want to have this model, you can run the script at the end of the article. We will create a mask on the subsystem. To do so:

• Step 1: Right click on the subsystem > Mask > Create Mask …
• Step 2: The following window will open:

• Step 3: Go to Documentation if you want to add a description to your subsystem.

If you click “Apply” and double click the block “Subsystem” instead of entering inside the block, you will merely see the information you just entered in the “Documentation” tab of your mask.

Script to create the model “mySimpleModel.slx”:

modelName = 'mySimpleModel';

% create and open the new test model
open_system(new_system(modelName));

offset = 100;
hSubsystems = 60;

% position Sine Wave
xSW= 30;
ySW = 30;
wSW = 30;
hSW = 30;
posSW= [xSW ySW xSW+wSW ySW+hSW];

blockName = 'Sine Wave';

% create a subsytem with I/O
inputPort = get_param([modelName '/In1'], 'handle');
outputPort = get_param([modelName '/Out1'], 'handle');
subSystemContent = [inputPort outputPort];

% delete the I/O created in modelName
delete_line(modelName,'In1/1','Subsystem/1');
delete_line(modelName,'Subsystem/1','Out1/1');
delete_block([modelName '/In1']);
delete_block([modelName '/Out1']);

% add line between the Input and Output ports
add_line(modelName, 'Sine Wave/1', 'Subsystem/1', 'autorouting', 'on');

% position Subsystem
wSubsystem = 8;
posSubsystem = posSW;
posSubsystem(1) = posSubsystem(1)+offset;
posSubsystem(2) = posSW(2)-(hSubsystems-hSW)/2;
posSubsystem(3) = posSubsystem(3)+offset+wSubsystem;
posSubsystem(4) = posSubsystem(2)+hSubsystems;
set_param([modelName '/Subsystem'],'Position', posSubsystem);

% position inport
pathInport = [modelName '/Subsystem/In1'];
currentPos = get_param(pathInport, 'Position');
currentHeight = currentPos(4) - currentPos(2);
currentWidth = currentPos(3) - currentPos(1);
posInport(1) = posSW(1);
posInport(2) = posSW(2);
posInport(3) = posInport(1)+currentWidth;
posInport(4) = posInport(2)+currentHeight;
set_param(pathInport,'Position', posInport);

currentHeight = currentPos(4) - currentPos(2);
currentWidth= currentPos(3) - currentPos(1);

% add line between the Input and Output ports

blockName = 'Constant';
pathConstant = [modelName '/Subsystem/' blockName];
currentPos = get_param(pathConstant, 'Position');
currentHeight = currentPos(4) - currentPos(2);
currentWidth = currentPos(3) - currentPos(1);
posConstant(1) = posSW(1);
posConstant(2) = posSW(2)+offset/2;
posConstant(3) = posConstant(1)+currentWidth;
posConstant(4) = posConstant(2)+currentHeight;
set_param(pathConstant,'Position', posConstant);

% add line between the Input and Output ports

% position outport
blockName = 'Out1';
pathOutport = [modelName '/Subsystem/' blockName];
currentPos = get_param(pathOutport, 'Position');
currentHeight = currentPos(4) - currentPos(2);
currentWidth = currentPos(3) - currentPos(1);
posOutport(3) = posOutport(1)+currentWidth;
posOutport(4) = posOutport(2)+currentHeight;
set_param(pathOutport,'Position', posOutport);

% add line between the Input and Output ports

blockName = 'Scope';
pathScope = [modelName '/' blockName];
currentPos = get_param(pathScope, 'Position');
currentHeight = currentPos(4) - currentPos(2);
currentWidth = currentPos(3) - currentPos(1);
posScope(1) = posSubsystem(1) + offset;
posScope(2) = posSubsystem(2) + (posSubsystem(4) - posSubsystem(2))/2 - currentHeight/2;
posScope(3) = posScope(1)+currentWidth;
posScope(4) = posScope(2)+currentHeight;
set_param(pathScope,'Position', posScope);

% add line between the Input and Output ports
add_line(modelName, 'Subsystem/1', [blockName '/1'], 'autorouting', 'on');