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
directory:
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. nodes p = foundation.electrical.electrical; % +:left n = foundation.electrical.electrical; % -:right end variables i = { 0, 'A' }; % Current v = { 0, 'V' }; % Voltage end parameters R = { 1, 'Ohm' }; % Resistance end branches i : p.i -> n.i; end equations assert(R>0) v == p.v - n.v; v == i*R; end end
Tip
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 directory.
To deploy this component as a block in your model:
Open or create a model.
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
.
Double-click the block to open the source file selector dialog box.
Click to open the browser. The browser opens in the
current working directory 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 preview pane.
Tip
Instead of browsing, you can type my_resistor
directly
into the text field. In this case, however, the preview pane does not
automatically get updated. If you want to preview the block name,
description, or source code, click .
Click Apply. The block icon and dialog box get updated, based on the selected source component.