Switch Between Different Source Components
This example shows how you can try out several variants of a component in your model by pointing the Simscape Component block to different component files.
The component files used in this example are capacitor models with different levels of fidelity, to allow exploration of the effect of losses and nonlinearity. The source files are part of your product installation, located in the following package directory:
matlabroot is the MATLAB® root directory on your machine, as returned by entering
in the MATLAB Command Window. For more information about these capacitor models, see Case Study — Basic Custom Block Library.
To test capacitor models of different fidelity:
To create a new model with optimal settings for physical modeling, in the MATLAB Command Window, type:
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 says
Double-click the block to open the source file selector dialog box.
Click and navigate to the directory containing the capacitor component files.
IdealCapacitor.sscfile 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.
Because the component file resides in a package, the file name in the selector dialog box field is the full name, starting from the package root.
Click OK. The block icon gets updated, based on the selected source component.
+Capacitorspackage directory contains image files, with the names corresponding to the Simscape™ component files, that define customized block icons. Therefore, when you point the Simscape Component block to the
IdealCapacitor.sscsource file, it uses the
IdealCapacitor.jpgin the same directory as the block icon. For details, see Customize the Block Icon.
Build the test model and connect the blocks as shown in the following diagram.
Open the scope and simulate the model.
The Simscape Component block points to an ideal capacitor component. Simulation results show that, when the switch is flipped at t=5 seconds, the capacitor delivers 2.5 A to the load.
To switch to another capacitor model, open the Simscape Component block dialog box and click Choose source.
The source file selector dialog box opens, displaying the preview of the currently selected component.
Click . The browser opens in the
+Capacitorsdirectory, because it contains the currently selected component.
IdealUltraCapacitor.sscfile 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.
Click OK. The block icon in the model diagram updates to reflect the new source component.
Rerun the simulation.
Simulation results show that, when the switch is flipped at t=5 seconds, the current delivered to the load is less than 2.5 A.
To make the effect more pronounced, open the block dialog box and increase the Rate of change of C with voltage V parameter value to 0.8 F/V.