Search code examples
matlabsimulink

Number of blocks in a Simulink model


How can I know the number of blocks or subsystems of the same kind, in a Simulink model, from Matlab (.m file)?

Thanks for your help.


Solution

  • See

    >> doc sldiagnostics
    

    and in particular

    >> nBlocks = sldiagnostics('modelname','CountBlocks');
    

    Note that sldiagnostics tells you how many of each type of block, so you'll need to parse it out, and do some math, to get the total block count.

    There is a discussion of doing something similar here