メインコンテンツ

このページの内容は最新ではありません。最新版の英語を参照するには、ここをクリックします。

Simulink Report Generator レポートの作成

Simulink® Report Generator™ レポート API は、モデルとシミュレーションのデータを検索し書式設定するオブジェクトから構成されています。これらのオブジェクトを MATLAB® レポート API オブジェクトおよび DOM API オブジェクトと共に使用して、Simulink のモデルとシミュレーションに関するレポートを生成する MATLAB プログラムを作成できます。この例では、Simulink レポート API と MATLAB レポート API を使用して MATLAB プログラムを作成する方法を説明します。このプログラムは、Simulink モデルのコンテンツに関するレポートを生成します。レポートには次のセクションが含まれます。

  • タイトル ページ

  • 目次

  • ルート システムの章 — ルート ブロック線図と、ルート ブロック線図内にある各ブロックのプロパティが含まれる。

  • サブシステムの章 — モデルの各サブシステムのブロック線図とブロック プロパティが含まれる。

  • Stateflow® チャートの章 — モデル内のチャートと各チャートのチャート オブジェクトのプロパティが含まれる。

レポートの作成

レポート API、ファインダー API、DOM API の関数の完全修飾名を使用せずに済むようにするには、次のステートメントを使用します。たとえば、slreportgen.finder.BlockFinder を使用する代わりに、BlockFinder を使用できます。

import slreportgen.report.*
import slreportgen.finder.*
import mlreportgen.report.*

sf_car モデルを読み込みます。

model = load_system("sf_car");

Simulink レポート コンストラクターslreportgen.report.Reportを使用して、レポートの内容を保持するレポート オブジェクトを作成します。このコンストラクターと MATLAB レポート コンストラクター mlreportgen.report.Report を区別するには、コンストラクターの名前を完全に修飾しなければなりません。レポートの名前を、sdd_ の後にモデルの Name プロパティの値が続くよう設定します。

rpt = slreportgen.report.Report("sdd_" + get_param(model,"Name"),"pdf");

タイトル ページの追加

タイトル ページ レポーター コンストラクターmlreportgen.report.TitlePageを使用して、タイトル ページを作成します。TitleSubtitle、および Author の各プロパティを、レポート タイトル、サブタイトル、作成者を指定する文字配列にそれぞれ設定します。

ブロック線図レポーター コンストラクターslreportgen.report.Diagramを使用して、モデルのブロック線図のスナップショットを作成します。このレポーターは、モデルのブロック線図のイメージを生成します。このイメージをレポートのタイトル ページに含めるには、タイトル ページ レポーターの Image プロパティにブロック線図レポーターを割り当てます。続いて、タイトル ページをレポートに追加します。

tp = TitlePage;
tp.Title = upper(get_param(model,"Name"));
tp.Subtitle = "System Design Description";
tp.Author = "MathWorks";
tp.Image = Diagram(model);
append(rpt,tp);

Report title page with title, subtitle, author, and model diagram.

目次の追加

目次レポーター コンストラクターmlreportgen.report.TableOfContentsを使用してレポートの目次を作成します。目次レポーターをレポートに追加します。

toc = TableOfContents;
append(rpt,toc);

Table of contents showing chapters and subsections

ルート システムの章の追加

章コンストラクターmlreportgen.report.Chapterを使用して、Title プロパティと Content プロパティに基づいて章を作成します。レポーターは、章タイトルに番号を付け、章ページのヘッダー、フッター、およびページ番号を生成します。

モデルのブロック線図レポーターを章に追加します。このレポーターは、章に追加するブロック線図のイメージを返します。

ch = Chapter("Title","RootSystem");
append(ch,Diagram(model));

Block diagram image displaying below chapter name RootSystem

ルートシステムの各ブロックの章の追加

ブロック ファインダー コンストラクターslreportgen.finder.BlockFinderを使用して、ルートのブロック線図のブロック ファインダーを作成します。次に、find メソッドを使用して、slreportgen.finder.BlockResultオブジェクトの配列を返します。各オブジェクトにはブロックが 1 つ含まれます。

ブロックの結果オブジェクトをループ処理します。各結果に対して、節レポーターmlreportgen.report.Sectionを作成し、番号付けされたレポートの節を生成します。節の Title プロパティを、節がレポートするブロックの名前に設定します。

現在のブロックの結果を節レポーターに追加して、節レポーターの Content プロパティをslreportgen.report.SimulinkObjectPropertiesレポーターに設定します。このレポーターは現在のブロックのプロパティ テーブルを生成し、それを節に追加します。各節を親の章に追加します。その後、章をレポートに追加します。

blkFinder = BlockFinder(model);
blocks = find(blkFinder);
for block = blocks
    section = Section("Title", ...
       strrep(block.Name,newline," "));
    append(section,block);
    append(ch,section);
end
append(rpt,ch);

Subsections of the report with tables of properties inserted in each subsection

サブシステムの章の追加

モデルのサブシステムと各サブシステム内のブロックについての章を作成します。

ch = Chapter("Title","Subsystems");

モデル内のすべてのサブシステムを検索します。システム ブロック線図ファインダーslreportgen.finder.SystemDiagramFinderは、slreportgen.finder.DiagramResultオブジェクトの配列を返します。それぞれのオブジェクトには、サブシステムのスナップショットを作成する Diagram レポーターが含まれます。

sysdiagFinder = SystemDiagramFinder(model);
sysdiagFinder.IncludeRoot = false;

Chapter titled Subsystems, followed by subsection titled Engine, which contains a snapshot of subsystem diagram, and another subsection titled Ti which contains a table of properties

while ループを使用して、各サブシステムについて、章内の節を作成します。各サブシステムでブロックとブロック要素を検索します。ブロック要素のテーブルを章内の各節に追加し、各節を章に追加します。その後、章をレポートに追加します。

while hasNext(sysdiagFinder)
    system = next(sysdiagFinder);
    section1 = Section("Title",system.Name);
    append(section1,system);
    
    blkFinder1 = BlockFinder(system);
    elems = find(blkFinder1);
    for elem = elems
       section2 = Section("Title",...
           strrep(elem.Name,newline," "));
       append(section2,elem);
       append(section1,section2);
    end
    append(ch,section1);
end
append(rpt,ch);

Subsection titled Vehicle, which contains a block diagram, and another subsection titled brake torque which contains a table of properties

Stateflow チャートとオブジェクトの章の追加

章を作成します。チャート ファインダーslreportgen.finder.ChartDiagramFinderを使用して、モデル内の Stateflow チャートを検索します。while ループを使用して各チャートの節を追加します。ブロック線図要素ファインダーslreportgen.finder.StateflowDiagramElementFinderを使用して、各チャートの要素を検索して、節にそれらを追加します。次に、節を章に追加し、章をレポートに追加します。

ch = Chapter("Title", "Stateflow Charts");

chdiagFinder = ChartDiagramFinder(model);
while hasNext(chdiagFinder) 
   chart = next(chdiagFinder); 
   section = Section("Title",chart.Name);
   append(section,chart);

   objFinder = StateflowDiagramElementFinder(chart);
   sfObjects = find(objFinder);
   for sfObj = sfObjects
       title = sfObj.Name;
       if isempty(title)
          title = sfObj.Type;
       end
       objSection = Section("Title",title);
       append(objSection,sfObj);
       append(section,objSection);
   end
   append(ch,section);
end
append(rpt,ch);

Chapter title Stateflow Charts with subsections for each Stateflow chart, followed by tables of properties

レポートの生成

レポートを閉じて、レポートを実行し、モデルを閉じます。

close(rpt);
rptview(rpt);
close_system(model);

参考