symReadSSCVariables
Load variables from Simscape component
Syntax
Description
[
returns
cell arrays containing the names, values, and units of all variables
from the Simscape™ component called names
,values
,units
]
= symReadSSCVariables(componentName
)componentName
.
[
returns the names as symbolic functions of variable names
,values
,units
]
= symReadSSCVariables(componentName
,'ReturnFunctions',true)t
.
Examples
Variables of Simscape Component
Load the names, values, and units of the variables of a Simscape component.
Suppose you have the Simscape component friction.ssc
in
your current folder.
type('friction.ssc');
component friction < foundation.mechanical.rotational.branch parameters brkwy_trq = { 25, 'N*m' }; % Breakaway friction torque Col_trq = { 20, 'N*m' }; % Coulomb friction torque visc_coef = { 0.001, 'N*m*s/rad' }; % Viscous friction coefficient trans_coef = { 10, 's/rad' }; % Transition approximation coefficient vel_thr = { 1e-4, 'rad/s' }; % Linear region velocity threshold end parameters (Access=private) brkwy_trq_th = { 24.995, 'N*m' }; % Breakaway torque at threshold velocity end function setup % Parameter range checking if brkwy_trq <= 0 pm_error('simscape:GreaterThanZero','Breakaway friction torque' ) end if Col_trq <= 0 pm_error('simscape:GreaterThanZero','Coulomb friction torque' ) end if Col_trq > brkwy_trq pm_error('simscape:LessThanOrEqual','Coulomb friction torque',... 'Breakaway friction torque') end if visc_coef < 0 pm_error('simscape:GreaterThanOrEqualToZero','Viscous friction coefficient') end if trans_coef <= 0 pm_error('simscape:GreaterThanZero','Transition approximation coefficient') end if vel_thr <= 0 pm_error('simscape:GreaterThanZero','Linear region velocity threshold') end % Computing breakaway torque at threshold velocity brkwy_trq_th = visc_coef * vel_thr + Col_trq + (brkwy_trq - Col_trq) * ... exp(-trans_coef * vel_thr); end equations if (abs(w) <= vel_thr) % Linear region t == brkwy_trq_th * w / vel_thr; elseif w > 0 t == visc_coef * w + Col_trq + ... (brkwy_trq - Col_trq) * exp(-trans_coef * w); else t == visc_coef * w - Col_trq - ... (brkwy_trq - Col_trq) * exp(-trans_coef * abs(w)); end end end
Load the names, values, and units of the variables of
the component friction.ssc
.
[names,values,units] = symReadSSCVariables('friction.ssc');
In this example, all elements of the resulting cell arrays are scalars. You can convert the cell arrays to symbolic vectors.
names_sym = cell2sym(names)
names_sym = [ t, w]
values_sym = cell2sym(values)
values_sym = [ 0, 0]
Create individual symbolic variables from the elements of the cell array
names
in the MATLAB® workspace. This command creates the symbolic variables
t
and w
as sym
objects in the
workspace.
syms(names)
Variables of Simscape Component Returned as Functions
Load the names of the variables of a Simscape component
while converting them to symbolic functions of the variable t
.
Suppose you have the Simscape component source.ssc
in
your current folder.
type('source.ssc');
component source % Electrical Source % Defines an electrical source with positive and negative external nodes. % Also defines associated through and across variables. nodes p = foundation.electrical.electrical; % :top n = foundation.electrical.electrical; % :bottom end variables(Access=protected) i = { 0, 'A' }; % Current v = { 0, 'V' }; % Voltage end branches i : p.i -> n.i; end equations v == p.v - n.v; end end
Load the names of the variables of the component
source.ssc
by setting
'ReturnFunctions'
to true
.
[names,~,~] = symReadSSCVariables('source.ssc','ReturnFunctions',true);
In this example, all elements of the resulting cell arrays are scalars. You can convert the cell arrays to symbolic vectors.
names_symfun = cell2sym(names)
names_symfun = [ i(t), v(t)]
Create individual symbolic functions from the elements of the cell array
names
in the MATLAB workspace. This command creates the symbolic functions
i
and v
as symfun
objects, and their
variable t
as a sym
object in the
workspace.
syms(names)
Input Arguments
componentName
— Simscape component name
file name enclosed in single quotes
Simscape component name, specified as a file name enclosed
in single quotes. The file must have the extension .ssc
.
If you do not provide the file extension, symReadSSCVariables
assumes
it to be .ssc
. The component must be on the MATLAB path
or in the current folder.
Example: 'MyComponent.ssc'
Output Arguments
names
— Names of all variables of Simscape component
cell array
Names of all variables of a Simscape component, returned as a cell array.
Data Types: cell
values
— Values of all variables of Simscape component
cell array
Values of all variables of a Simscape component, returned as a cell array.
Data Types: cell
units
— Units of all variables of Simscape component
cell array
Units of all variables of a Simscape component, returned as a cell array.
Data Types: cell
Version History
Introduced in R2016a
See Also
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)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)