メインコンテンツ

sscnewfile

必須のキーワードとよく使用されるキーワードが取り込まれた新しい Simscape ファイルを作成する

説明

sscnewfile(name) は、既定のコンポーネント テンプレートを使用して、指定した名前 name のコンポーネントを作成します。この関数は、新しい Simscape™ ファイル name を現在のフォルダーに自動的に保存します。

sscnewfile(name,template_keyword) は、template_keyword で指定したドメイン固有のテンプレートを使用して、指定した名前 name のコンポーネントを作成します。使用可能なキーワードのリストを表示するには、-list オプションを使用します。この関数は、新しい Simscape ファイル name を現在のフォルダーに自動的に保存します。

sscnewfile(name,template_file) は、テンプレートとして同じタイプのファイル template_file を使用し、指定した名前 name のコンポーネント、ドメイン、または関数のファイルを作成します。テンプレート ファイル名には、ファイル パスを含める必要があります。simscape.template 名前空間にはさまざまなテンプレート ファイルが用意されていますが、任意の Simscape ファイルをテンプレートとして使用することができます。関数は、テンプレート ファイルの内容を新しいファイルにコピーし、コンポーネント、ドメイン、または関数の名前を name に置き換えて、新しいファイルを現在のフォルダーに保存します。

sscnewfile -list は、使用可能なテンプレート キーワードのリストを返し、simscape.template 名前空間で使用可能なすべてのファイルをリストします。

すべて折りたたむ

既定のコンポーネント テンプレートを使用して MyComponent という名前のコンポーネントを作成し、現在のフォルダーに MyComponent.ssc という名前で保存します。

sscnewfile('MyComponent')

新しいファイルが MATLAB® エディターで開きます。

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

新しいコンポーネントを作成する際の開始点としてこのファイルを使用します。% で始まる行はコメントです。必要に応じて、実際の宣言や方程式に置き換えます。不要なセクションを削除したり、componentsconnectionsintermediates などの他のセクションを追加したりすることもできます。

電気ドメイン用の既定のコンポーネント テンプレートを使用して MyResistor という名前のコンポーネントを作成し、現在のフォルダーに MyResistor.ssc という名前で保存します。

sscnewfile('MyResistor','electrical')

新しいファイルが MATLAB エディターで開きます。

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

新しいコンポーネントを作成する際の開始点としてこのファイルを使用します。% で始まる行はコメントです。必要に応じて、実際の宣言や方程式に置き換えます。カスタム抵抗を作成する例については、Simscape 言語での線形抵抗のモデル化を参照してください。

Foundation 気体ドメインをテンプレートとして使用して MyGasDomain という名前のドメインを作成し、現在のフォルダーに MyGasDomain.ssc という名前で保存します。

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

新しいファイルが MATLAB エディターで開きます。新しいドメインの名前は MyGasDomain で、これは name 引数と一致しています。ファイルの残りの部分は、Foundation 気体ドメインの定義のコピーです。

新しいドメインを作成する際の開始点としてこのファイルを使用します。アプリケーションに合わせて、ドメインのパラメーターやプロパティを変更します。

テンプレート キーワードと、simscape.template 名前空間で使用可能なテンプレート ファイルをリストします。

sscnewfile -list
--------------------------------------------------------------------------
Template keywords
---------------------------------------------------------------------------------------
    angle_based_rotational          simscape.template.rotational.two_port
    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.rotational
---------------------------------------------------------
    two_port    Two-port angle-based rotational 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

これらのファイルのいずれかを新しいコンポーネントのテンプレートとして使用するには、2 番目の入力引数としてファイルの絶対パスと名前 (たとえば、'simscape.template.gas.two_port_dynamic') を指定します。

入力引数

すべて折りたたむ

新しいコンポーネント、ドメイン、または関数の名前。文字ベクトルまたは string スカラーとして指定します。この名前は、作成される新しい Simscape ファイルの名前としても使用されます。ファイルは現在のフォルダーに自動的に保存されます。

例: 'MyResistor'

データ型: char | string

新しいファイルのテンプレートとして使用するコンポーネント ファイルのタイプ。文字ベクトルまたは string スカラーとして指定します。これらのキーワードを使用して、特定のドメイン タイプのコンポーネント ファイルを作成します。使用可能なキーワードのリストを表示するには、-list オプションを使用します。

例: 'electrical'

データ型: char | string

Simscape のコンポーネント、ドメイン、または関数の名前。文字ベクトルまたは string スカラーとして指定します。ファイル名には、最上位の名前空間フォルダーからのファイルのパスを含める必要があります。ファイルが MATLAB パス上にある場合は、代わりに絶対ファイル パスを指定することもできます。作成される新しいファイルでは、この Simscape ファイルがテンプレートとして使用されます。

例: 'foundation.electrical.elements.resistor'

データ型: char | string

バージョン履歴

R2019b で導入