symWriteSSC
Create new Simscape component
Syntax
Description
symWriteSSC(
creates
a new Simscape™ component newComponentName
,templateComponentName
,eqns
)newComponentName
using
an existing component templateComponentName
as
a template and adding eqns
. Thus, the new component
has both the existing equations taken from the template component
and the added equations.
symWriteSSC(
uses
additional options specified by one or more newComponentName
,templateComponentName
,eqns
,Name,Value
)Name,Value
pair
arguments.
Examples
Create Component with Additional Equation
Create a new Simscape component by using an existing component as a template and adding an equation.
Suppose you have the Simscape component spring.ssc
in
your current folder.
type('spring.ssc');
component spring < foundation.mechanical.rotational.branch parameters spr_rate = { 10, 'N*m/rad' }; end variables phi = { value = { 0, 'rad'}, priority = priority.high }; end function setup if spr_rate <= 0 pm_error('simscape:GreaterThanZero','Spring rate' ) end end equations w == phi.der; t == spr_rate*phi; end end
Create symbolic variables with names of the parameters
and variables of the component you are going to use when creating
new equations. Also create a symbolic variable, u
,
to denote the energy of the rotational spring.
syms spr_rate phi u
Create the equation defining the energy u
.
eq = u == spr_rate*phi^2/2;
Create the new component, myRotationalSpring.ssc
, that
is a copy of the component spring.ssc
with an additional
equation defining the energy of the rotational spring.
symWriteSSC('myRotationalSpring.ssc','spring.ssc',eq)
Warning: Equations contain undeclared variables 'u'. > In symWriteSSC (line 94)
symWriteSSC
creates the component
myRotationalSpring.ssc
.
type('myRotationalSpring.ssc');
component myRotationalSpring parameters spr_rate = { 10, 'N*m/rad' }; end variables phi = { value = { 0, 'rad'}, priority = priority.high }; end function setup if spr_rate <= 0 pm_error('simscape:GreaterThanZero','Spring rate' ) end end equations w == phi.der; t == spr_rate*phi; u == phi^2*spr_rate*(1.0/2.0); end end
Add Component Title and Description
Create a Simscape component with the title and descriptive text different from those of the template component.
Suppose you have the Simscape component spring.ssc
in
your current folder. This component does not have any title or descriptive
text.
type('spring.ssc');
component spring < foundation.mechanical.rotational.branch parameters spr_rate = { 10, 'N*m/rad' }; end variables phi = { value = { 0, 'rad'}, priority = priority.high }; end function setup if spr_rate <= 0 pm_error('simscape:GreaterThanZero','Spring rate' ) end end equations w == phi.der; t == spr_rate*phi; end end
Create symbolic variables with names of the parameters
and variables of the component you are going to use when creating
new equations. Also create a symbolic variable, u
,
to denote the energy of the rotational spring.
syms spr_rate phi u
Create the equation defining the energy u
.
eq = u == spr_rate*phi^2/2;
Create the new component, myRotationalSpring.ssc
, based
on the spring.ssc
component. Add the equation
eq
, the title “Rotational Spring”, and
a few lines of descriptive text to the new component.
symWriteSSC('myRotationalSpring.ssc','spring.ssc',eq,... 'H1Header','% Rotational Spring',... 'HelpText',{'% The block represents an ideal mechanical rotational linear spring.',... '% Connections R and C are mechanical rotational conserving ports.'... '% The block positive direction is from port R to port C. This means'... '% that the torque is positive if it acts in the direction from R to C.'})
Warning: Equations contain undeclared variables 'u'. > In symWriteSSC (line 94)
symWriteSSC
creates the component
myRotationalSpring.ssc
.
type('myRotationalSpring.ssc');
component myRotationalSpring % Rotational Spring % The block represents an ideal mechanical rotational linear spring. % Connections R and C are mechanical rotational conserving ports. % The block positive direction is from port R to port C. This means % that the torque is positive if it acts in the direction from R to C. parameters spr_rate = { 10, 'N*m/rad' }; end variables phi = { value = { 0, 'rad'}, priority = priority.high }; end function setup if spr_rate <= 0 pm_error('simscape:GreaterThanZero','Spring rate' ) end end equations w == phi.der; t == spr_rate*phi; u == phi^2*spr_rate*(1.0/2.0); end end
Input Arguments
newComponentName
— Name of Simscape component to create
file name enclosed in single quotes
Name of Simscape component to create, specified as a file
name enclosed in single quotes. File must have the extension .ssc
.
If you do not provide file extension, symWriteSSC
assumes
it to be .ssc
. If you do not specify the absolute
path, symWriteSSC
creates the new component in
the current folder.
Example: 'MyNewComponent.ssc'
templateComponentName
— Name of template Simscape component
file name enclosed in single quotes
Name of template Simscape component, specified as a file
name enclosed in single quotes. File must have the extension .ssc
.
If you do not provide the file extension, symWriteSSC
assumes
it to be .ssc
. The component must be on the MATLAB® path
or in the current folder.
Example: 'TemplateComponent.ssc'
eqns
— Symbolic equations
row vector
Symbolic equations, specified as a row vector.
Example: [ y(t) == diff(x(t), t), m*diff(y(t), t, t)
+ b*y(t) + k*x(t) == F]
Name-Value Arguments
Specify optional pairs of arguments as
Name1=Value1,...,NameN=ValueN
, where Name
is
the argument name and Value
is the corresponding value.
Name-value arguments must appear after other arguments, but the order of the
pairs does not matter.
Before R2021a, use commas to separate each name and value, and enclose
Name
in quotes.
Example: symWriteSSC('myComp.ssc','template.ssc',eq,'H1Header','%
New title','HelpText',{'% Description of the','% new component'})
H1Header
— Title
row vector of characters
Title specified as a row vector of characters (type char
)
starting with %. If the first character is not %, then symWriteSSC
adds
%.
If the template component has a title and you use H1Header
,
the new component will have the title specified by H1Header
.
If the template component has a title and you call symWriteSSC
without H1Header
,
the new component will have the same title as the template component.
Example: 'H1Header','% New title'
HelpText
— Descriptive text
cell array of row vectors of characters
Descriptive text, specified as a cell array of row vectors of
characters. Each row vector must start with %. If the first character
is not %, then symWriteSSC
adds %.
If the template component has descriptive text and you use HelpText
,
the new component will have only the text specified by HelpText
.
In this case, symWriteSSC
does not copy the descriptive
text of the template component to the new component. If the template
component has a title and you call symWriteSSC
without HelpText
,
the new component will have the same descriptive text as the template
component.
Example: 'HelpText',{'% Description of the','% new component'}
Version History
Introduced in R2016a
See Also
symReadSSCParameters
| symReadSSCVariables
| simscapeEquation
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)