Main Content

symReadSSCVariables

Simscape コンポーネントからの変数の読み込み

説明

[names,values,units] = symReadSSCVariables(componentName) は、componentName と呼ばれる Simscape™ コンポーネントから、すべての変数の名前、値および単位を含む cell 配列を返します。

[names,values,units] = symReadSSCVariables(componentName,'ReturnFunctions',true) は、名前を変数 t のシンボリック関数として返します。

すべて折りたたむ

Simscape コンポーネントの変数の名前、値および単位を読み込みます。

現在のフォルダーに Simscape コンポーネント friction.ssc があるとします。

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

コンポーネント friction.ssc の変数の名前、値および単位を読み込みます。

[names,values,units] = symReadSSCVariables('friction.ssc');

この例では、結果の cell 配列のすべての要素がスカラーです。cell 配列はシンボリック ベクトルに変換できます。

names_sym = cell2sym(names)
names_sym =
[ t, w]
values_sym = cell2sym(values)
values_sym =
[ 0, 0]

MATLAB® ワークスペースにある cell 配列 names の要素から個々のシンボリック変数を作成します。このコマンドは、シンボリック変数 twsym オブジェクトとしてワークスペースに作成します。

syms(names)

Simscape コンポーネントの変数の名前を読み込むと共に、それらを変数 t のシンボリック関数に変換します。

現在のフォルダーに Simscape コンポーネント source.ssc があるとします。

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

'ReturnFunctions'true に設定して、コンポーネント source.ssc の変数の名前を読み込みます。

[names,~,~] = symReadSSCVariables('source.ssc','ReturnFunctions',true);

この例では、結果の cell 配列のすべての要素がスカラーです。cell 配列はシンボリック ベクトルに変換できます。

names_symfun = cell2sym(names)
names_symfun =
[ i(t), v(t)]

MATLAB ワークスペースにある cell 配列 names の要素から個々のシンボリック関数を作成します。このコマンドは、シンボリック関数 ivsymfun オブジェクト、変数 tsym オブジェクトとしてワークスペースに作成します。

syms(names)

入力引数

すべて折りたたむ

Simscape コンポーネント名。一重引用符で囲まれたファイル名として指定します。ファイルには拡張子 .ssc が付いていなければなりません。ファイル拡張子を指定しない場合、symReadSSCVariables によって .ssc であると仮定されます。コンポーネントは MATLAB パス上または現在のフォルダーになければなりません。

例: 'MyComponent.ssc'

出力引数

すべて折りたたむ

Simscape コンポーネントのすべての変数の名前。cell 配列として返されます。

データ型: cell

Simscape コンポーネントのすべての変数の値。cell 配列として返されます。

データ型: cell

Simscape コンポーネントのすべての変数の単位。cell 配列として返されます。

データ型: cell

バージョン履歴

R2016a で導入