Main Content

sscnewfile

Create new Simscape file populated by required and commonly used keywords

Description

sscnewfile(name) creates a component with the specified name using the default component template. The function automatically saves the new Simscape™ file, name, in the current folder.

example

sscnewfile(name,template_keyword) creates a component with the specified name using the domain-specific template specified by template_keyword. For a list of available keywords, use the -list option. The function automatically saves the new Simscape file, name, in the current folder.

example

sscnewfile(name,template_file) creates a component, domain, or function file with the specified name using a file of the same type, template_file, as the template. The template file name must include the file path. Various template files are available in the simscape.template namespace; however, you can use any Simscape file as a template. The function copies the contents of the template file into the new file, replaces the name of the component, domain, or function with name, and saves the new file in the current folder.

example

sscnewfile -list returns a list of available template keywords and lists all the files available in the simscape.template namespace.

example

Examples

collapse all

Create a component named MyComponent using the default component template and save it as MyComponent.ssc in the current folder.

sscnewfile('MyComponent')

The new file opens in the MATLAB® Editor.

component MyComponent
% Simple Simscape component

parameters
   % Add parameters here
   % p = { value , 'unit' }; % Parameter name
end

nodes
   % A = namespace_name.domain_name; % A:left
   % B = namespace_name.domain_name; % B:right
end

variables
   % x = { value , 'unit' }; % Through variable name
   % y = { value , 'unit' }; % Across variable name
end

branches
   % x : A.x -> B.x;
end

equations
   % Add equations here
   % y == A.y - B.y;
   % x == fcn(y);
end

end

Use this file as a starting point for authoring the new component. Lines that start with % are comments. Replace them with actual declarations and equations, as needed. You can also delete unnecessary sections and add other sections, such as components, connections, or intermediates.

Create a component named MyResistor using the default component template for the electrical domain and save it as MyResistor.ssc in the current folder.

sscnewfile('MyResistor','electrical')

The new file opens in the MATLAB Editor.

component MyResistor
% Two-port electrical component

parameters
   % Add parameters here
   % R = { 1, 'Ohm' }; % Resistance
end

nodes
    p = foundation.electrical.electrical; % +:left
    n = foundation.electrical.electrical; % -:right
end

variables
    i = { 0, 'A' }; % Current
    v = { 0, 'V' }; % Voltage
end

branches
    i : p.i -> n.i;
end

equations
    % Voltage difference between nodes
    v == p.v - n.v;

    % Add equations here
    % v == i*R;
end

end

Use this file as a starting point for authoring the new component. Lines that start with % are comments. Replace them with actual declarations and equations, as needed. For an example of creating a custom resistor, see Model Linear Resistor in Simscape Language.

Create a domain named MyGasDomain using the Foundation gas domain as a template and save it as MyGasDomain.ssc in the current folder.

sscnewfile('MyGasDomain', 'foundation.gas.gas')

The new file opens in the MATLAB Editor. The name of the new domain is MyGasDomain, matching the name argument. The rest of the file is a copy of the Foundation gas domain definition.

Use this file as a starting point for authoring the new domain. Modify the domain parameters and properties to suit your application.

List the template keywords and the template files available in the simscape.template namespace.

sscnewfile -list
--------------------------------------------------------------------------
Template keywords
---------------------------------------------------------------------------------------
    default                         simscape.template.simple_component
    electrical                      simscape.template.electrical.two_port
    gas                             simscape.template.gas.two_port_steady
    magnetic                        simscape.template.magnetic.two_port
    moist_air                       simscape.template.moist_air.two_port_steady
    position_based_translational    simscape.template.translational.two_port
    rotational                      simscape.template.mechanical.rotational.two_port
    signal                          simscape.template.signal.simple_component
    thermal                         simscape.template.thermal.two_port
    thermal_liquid                  simscape.template.thermal_liquid.two_port_steady
    translational                   simscape.template.mechanical.translational.two_port
    two_phase_fluid                 simscape.template.two_phase_fluid.two_port_steady
-------------------------------------------------
Files in namespace simscape.template
-------------------------------------------------
    simple_component    Simple Simscape component
    simple_function     
-----------------------------------------------
Files in namespace simscape.template.electrical
-----------------------------------------------
    two_port    Two-port electrical component
------------------------------------------------------
Files in namespace simscape.template.gas
------------------------------------------------------
    two_port_dynamic    Two-port dynamic gas component
    two_port_steady     Two-port steady gas component
---------------------------------------------
Files in namespace simscape.template.magnetic
---------------------------------------------
    two_port    Two-port magnetic component
----------------------------------------------------------
Files in namespace simscape.template.mechanical.rotational
----------------------------------------------------------
    two_port    Two-port rotational component
-------------------------------------------------------------
Files in namespace simscape.template.mechanical.translational
-------------------------------------------------------------
    two_port    Two-port translational component
------------------------------------------------------------
Files in namespace simscape.template.moist_air
------------------------------------------------------------
    two_port_dynamic    Two-port dynamic moist_air component
    two_port_steady     Two-port steady moist air component
--------------------------------------------------------------
Files in namespace simscape.template.signal
--------------------------------------------------------------
    simple_component    Simple component with physical signals
--------------------------------------------
Files in namespace simscape.template.thermal
--------------------------------------------
    two_port    Two-port thermal component
-----------------------------------------------------------------
Files in namespace simscape.template.thermal_liquid
-----------------------------------------------------------------
    two_port_dynamic    Two-port dynamic thermal liquid component
    two_port_steady     Two-port steady thermal liquid component
---------------------------------------------------------------
Files in namespace simscape.template.translational
---------------------------------------------------------------
    two_port    Two-port position-based translational component
------------------------------------------------------------------
Files in namespace simscape.template.two_phase_fluid
------------------------------------------------------------------
    two_port_dynamic    Two-port dynamic two-phase fluid component
    two_port_steady     Two-port steady two-phase fluid component

To use one of these files as the template for a new component, specify the full path and name of the file as the second input argument, for example, 'simscape.template.gas.two_port_dynamic'.

Input Arguments

collapse all

Name of the new component, domain, or function, specified as a character vector or string scalar. This name also serves as the name of the new Simscape file being created. The file is automatically saved in the current folder.

Example: 'MyResistor'

Data Types: char | string

Type of component file to be used as the template for the new file, specified as a character vector or string scalar. Use these keywords to create component files for a specific domain type. For a list of available keywords, use the -list option.

Example: 'electrical'

Data Types: char | string

Name of a Simscape component, domain, or function, specified as a character vector or string scalar. The file name must include the path to the file from the top-level namespace folder. If the file is on the MATLAB path, you can specify the absolute file path instead. The new file being created will use this Simscape file as the template.

Example: 'foundation.electrical.elements.resistor'

Data Types: char | string

Version History

Introduced in R2019b