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 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
endCreate 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
endCreate 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
endCreate 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
endInput Arguments
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'
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'
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'})
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'
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.
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- 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)