MATLAB のハンドル クラスおよび System object のコード生成
この例では、ユーザー定義の System object™ のコードを生成する方法について説明し、コード生成レポートで生成されたコードを示します。
書き込み可能なフォルダーに System object
AddOne
を作成します。これはmatlab.System
からサブクラス化されるものです。AddOne.m
としてコードを保存します。classdef AddOne < matlab.System % ADDONE Compute an output value that increments the input by one methods (Access=protected) % stepImpl method is called by the step method function y = stepImpl(~,x) y = x+1; end end end
この System object を使用する関数を記述します。
function y = testAddOne(x) %#codegen p = AddOne(); y = p.step(x); end
このコードの MEX 関数を生成します。
codegen -report testAddOne -args {0}
-report
オプションにより、エラーや警告が発生しなくても、codegen
でコード生成レポートを生成することを指定します。-args
オプションにより、testAddOne
関数が 1 つのスカラーで double の入力を受け取ることを指定します。[レポートの表示] リンクをクリックします。
[MATLAB ソース] ペインで、
testAddOne
をクリックします。testAddOne
の変数の詳細を表示するには、[変数] タブをクリックします。addOne
のクラス定義を表示するには、[MATLAB ソース] ペインで、AddOne
をクリックします。