Main Content

Deploy a Component File in Block Diagram

This example shows how you can quickly transform a Simscape™ component file into a block in your model, without the extra steps of packaging the file and building a custom library.

Suppose you have the following Simscape file, named my_resistor, in your working folder:

component my_resistor
% Linear Resistor
% The voltage-current (V-I) relationship for a linear resistor is V=I*R,
% where R is the constant resistance in ohms.
% The positive and negative terminals of the resistor are denoted by the
% + and - signs respectively.

    p = foundation.electrical.electrical; % +:left
    n = foundation.electrical.electrical; % -:right
    i = { 0, 'A' };     % Current
    v = { 0, 'V' };     % Voltage
    R = { 1, 'Ohm' };   % Resistance

    i : p.i -> n.i;

    v == p.v - n.v;
    v == i*R;



This component implements a linear resistor. It is described in more detail in Model Linear Resistor in Simscape Language. You can copy the source from this page and save it as my_resistor.ssc in your working folder.

To deploy this component as a block in your model:

  1. Open or create a model.

  2. Open the Simscape > Utilities library and add the Simscape Component block to your model. At first, the block does not point to any component file. Therefore, it does not have any ports, and the block icon states it is Unspecified.

  3. Double-click the block to open the source file selector dialog box.

  4. Click to open the browser. The browser opens in the current working folder and lists only the files with the .ssc or .sscp extension. Select the my_resistor.ssc file and click Open. The name of the source file appears in the text field of the source file selector dialog box, and the block name, description, and the link to source code appear in the Description pane.

    The source component selection is applied immediately, regardless of whether you have the Auto Apply check box selected or not. The block icon and dialog box get updated, based on the selected source component.


    Instead of browsing, you can type my_resistor directly into the text field. In this case, however, the Description pane does not automatically get updated. If you want to view the block name, description, or source code, click . To view the block parameters, click the Settings tab.

Related Examples

More About