Main Content

Simulink.BlockDiagram.resizeBlocksToFitContent

Adjust block size to fit displayed value

Since R2024b

    Description

    resizedBlocks = Simulink.BlockDiagram.resizeBlocksToFitContent(sys) resizes blocks of these types in the model, library, or subsystem named sys to be large enough to fit the parameter value they display on their block icons:

    When the blocks are too small to display the parameter value, the blocks display a placeholder letter instead, for example, -K-.

    The function outputs the paths of the resized blocks as a cell array of character vectors. The Simulink.BlockDiagram.resizeBlocksToFitContent function does not act on blocks in model references.

    example

    resizedBlocks = Simulink.BlockDiagram.resizeBlocksToFitContent(sys,ReportOnly="true") outputs the paths of all blocks of the listed block types in sys that display placeholder letters. The function outputs the block paths as a cell array of character vectors. This syntax does not resize any blocks.

    resizedBlocks = Simulink.BlockDiagram.resizeBlocksToFitContent(sys,BlockList=blocksToResize) resizes all blocks in the block set specified by blocksToResize that are of the listed block types and display a placeholder letter. The function outputs the paths of the resized blocks as a cell array of character vectors.

    Examples

    collapse all

    This example shows how to programmatically resize all value-displaying blocks in a model to be large enough to display their values instead of placeholder letters.

    Open the sldemo_hardstop_resized model.

    model = "sldemo_hardstop_resized";
    open_system(model);

    At the top level of the model, the Gain block named Kspring and the Constant block named Normal Force are too small to display their values. Instead, the blocks respectively display the placeholder letters -K- and -C-. Programmatically select the blocks so that you can see where the blocks are located in the model.

    set_param(model+"/Kspring",Selected="on");
    set_param(model+"/Normal Force",Selected="on");

    Open the Friction Model subsystem.

    subsys = model+"/Friction Model";
    open_system(subsys);

    In the subsystem, the Gain blocks named Mu Static and Mu Kinetic are too small to display their values. Instead, the blocks display -K-.

    set_param(subsys+"/Mu Static",Selected="on");
    set_param(subsys+"/Mu Kinetic",Selected="on");

    Get the names of all the blocks that are too small to display their values.

    resizedBlocks = Simulink.BlockDiagram.resizeBlocksToFitContent(model,ReportOnly="true")
    resizedBlocks = 4×1 cell
        {'sldemo_hardstop_resized/Friction Model/Mu Kinetic'}
        {'sldemo_hardstop_resized/Friction Model/Mu Static' }
        {'sldemo_hardstop_resized/Kspring'                  }
        {'sldemo_hardstop_resized/Normal Force'             }
    
    

    Resize only the blocks in the subsystem named Friction Model that are too small to display their values. Use the find_system function to get the paths of the blocks in the subsystem.

    blocks = find_system(subsys);
    Simulink.BlockDiagram.resizeBlocksToFitContent(model,BlockList=blocks);

    Check the blocks again. The blocks in the subsystem now display values, but the blocks at the top level of the model still display placeholder letters.

    Resize all the blocks in the model that are too small to display their values.

    Simulink.BlockDiagram.resizeBlocksToFitContent(model);

    All blocks now display values instead of placeholder letters.

    Input Arguments

    collapse all

    Model, subsystem, or library in which to resize blocks, specified as a string or character vector.

    Example: "myModel"

    Data Types: string | char

    Name-Value Arguments

    collapse all

    Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

    Example: Simulink.BlockDiagram.resizeBlocksToFitContent(model,ReportOnly="true")

    Option to report block paths but not replace blocks, specified as "false" or "true". When ReportOnly is true, the function outputs the paths of all blocks in the specified model or from the specified list of blocks that display placeholder names but does not resize any blocks. When ReportOnly is false, the function outputs the same block paths and resizes the blocks.

    Example: "true"

    Data Types: char | string

    Set of blocks to resize, specified as block paths in a string array or a cell array of character vectors.

    Example: ["myModel/myBlock1","myModel/myBlock2"]

    Data Types: string | cell | char

    Output Arguments

    collapse all

    Resized blocks, returned as block paths specified as a cell array of character vectors.

    Version History

    Introduced in R2024b