Selecting Component File Directly from Block
The Simscape Component block lets you select a Simscape™ component file, and then instantly acquires the properties based on that source component file: name, description, parameters, variables, the block icon and appropriate ports. For more information on how the component file elements translate into the properties of the block, see Customizing the Block Name and Appearance.
Use the Simscape Component block to:
Quickly deploy a single Simscape component file as a block in your model, without the extra steps of packaging the file and building a custom library. For example, you wrote a component prototype yourself, got it from a colleague, or found it on MATLAB® Central. Save the file in your current working directory, or anywhere on the MATLAB path, and use it as a source file for a Simscape Component block in your model. For more information on valid locations of a source component file, see Component File Locations. For an example of this workflow, see Deploy a Component File in Block Diagram.
Try out different component implementations, to decide which implementation is most appropriate for your model. You can also use this workflow to test the differences between the old and new implementations of the same component. Instead of adding, deleting, and reconnecting different blocks in your model, you can use a single Simscape Component block and switch between the source component files. When you point a Simscape Component block to a different component file, the block properties change accordingly, to reflect the new source. For an example of this workflow, see Switch Between Different Source Components.
Quickly try out different ideas for a physical component and get instant feedback on the resulting block implementation. This workflow lets you interactively modify the component source and immediately see the changes by refreshing the resulting block. For an example of this workflow, see Prototype a Component and Get Instant Feedback.
Component File Locations
When you deploy a component file by using the Simscape Component block, the component file does not have to be in a package. However, the directory where the file resides has to be on the MATLAB path. If the file resides in a package, then the package parent directory must be on the MATLAB path.
If you browse to a component file that is not on the path, then, when you try to select it, a File Not On Path dialog opens. Click Add to add the appropriate directory to the MATLAB path.
The Add button is similar to the
addpath command, that is, it adds
the folder to the path only for the duration of the current MATLAB session. If you do not save the path and then open the model in a
subsequent session, the Simscape Component block becomes unresolved.
If the source component is located in the current working directory, then there is no requirement for it to be on the path. However, if you later try to open the model from another directory, the Simscape Component block also becomes unresolved.
It is good practice to keep the source component files that you want to reuse in a directory included in your permanent search path. For more information, see What Is the MATLAB Search Path?.
- Deploy a Component File in Block Diagram
- Switch Between Different Source Components
- Prototype a Component and Get Instant Feedback