Main Content


Import ladder diagram into a Simulink subsystem



mdlname = plcimportladder(filename)generates a Simulink® representation of the ladder diagram in the L5X file created using Rockwell Automation® IDEs such as RSLogix™ 5000 and Studio 5000.

[mdlname,mdllib,genbusscript] = plcimportladder(filename,Name,Value)generates a Simulink representation of the ladder diagram in the L5X file with properties specified using one or more Name,Value pair arguments.


collapse all

The following example demonstrates how to import a simple ladder diagram from an L5X file (simpleController.L5X) into the Simulink environment. Create the simpleController.L5X by using RSLogix 5000 IDE. The ladder diagram contains contacts and coils representing switches and motor. The following is a snapshot of the ladder diagram structure.

Use the plcladderimport function to import the created ladder diagram into Simulink. For this example, the program Name of the ladder is MainProgram and the MainRoutineName is MainRoutine.

[mdlName,mdlLib,busScript] = plcimportladder('simpleController.L5X','OpenModel','On')
mdlName =


mdlLib =


busScript =


The imported model contains a PLC Controller block named simpleController, followed by a Task block named MainTask and finally a Ladder Diagram Program block named MainProgram. The model imported into Simulink has blocks that implement the functionality of the contacts and coils.

You can traverse up these organizational blocks by double-clicking the Up to Parent POU element. The Program Variables spreadsheet contains the variables Start, Stop, and Motor. You can use this table to modify attributes of the variables such as Data Type, Initial Value, and size

Input Arguments

collapse all

Specifies the name of the ladder file to read. Depending on the location of your file, you can either specify the name of the file or provide the full or relative path. name.

Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside quotes. You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Example: [mdlName,mdlLib,genBusScript] = plcimportladder('sampleLadder.L5X','OpenModel','on','TopAOI','sampleAOI')

At the end of import process, the model is hidden by default. To keep the model open at the end of import, set the value of OpenModel to on.

Specify the function blocks that is to be imported. The software imports it into a ladder diagram 'runner' block.

Output Arguments

collapse all

Specifies the name of the generated Simulink model.

Specifies the name of the generated Simulink model library.

Specifies the name of the generated bus script.

Introduced in R2018a