メインコンテンツ

診断メッセージのカスタマイズ

診断ビューアーは、Simulink® モデルの実行時操作中に生成される診断メッセージを表示します。エラー メッセージは、コールバック、S-Function または MATLAB Function ブロックで MATLAB® エラー関数を使用してカスタマイズできます。

カスタム テキストの表示

この例では、MATLAB Function ブロックを使用してエラー メッセージをカスタマイズする方法を示します。

  1. Constant ブロック、MATLAB Function ブロック、および Display ブロックをもつモデルについて考えます。

    Simulink model using a MATLAB Function block.

  2. MATLAB Function ブロック エディターで、MATLAB Function ブロックへの入力が負の場合にカスタム メッセージ Signal is negative を表示する、check_signal という名前の関数を作成します。

    function y = check_signal(x)
    	if x < 0 
    		error('Signal is negative');
    	else
    		y = x;
    	end
    
  3. モデルのシミュレーションを実行します。

  4. MATLAB Function ブロックへの入力が負の場合、診断ビューアーにカスタム エラー メッセージが表示されます。

Diagnostic Viewer displaying the custom error message.

ファイル、フォルダー、ブロックへのハイパーリンクの作成

エラー メッセージにファイル、フォルダーまたはブロックへのハイパーリンクを作成するには、カスタマイズされたテキスト内のそれらの項目へのパスを含めます。

エラー メッセージの例ハイパーリンク
error('Error reading data from "C:/Work/designData.mat"')MATLAB エディターで、designData.data を開きます。
error('Could not find data in folder "C:/Work"')コマンド ウィンドウを開いて C:\Work を作業フォルダーとして設定します。
error('Error evaluating parameter in block "myModel/Mu"')モデル myModel のブロック Mu を表示します。

プログラムによるハイパーリンクの作成

この例では、MATLAB Function ブロックの関数 check_signal をカスタマイズして find_system 関数のドキュメンテーションへのハイパーリンクを表示する方法を示します。

  1. Constant ブロック、MATLAB Function ブロック、および Display ブロックをもつモデルについて考えます。

    Simulink model using a MATLAB Function block.

  2. MATLAB Function ブロック エディターで、MATLAB Function ブロックへの入力が負の場合に find_system 関数のドキュメンテーションへのハイパーリンクを表示する関数 check_signal を作成します。

    function y = check_signal(x)
    	if x < 0
    		error('See help for ...
                  <a href="matlab:doc find_system">find_system</a>');
    	else
    		y = x;
    	end
    
  3. モデルのシミュレーションを実行します。

  4. MATLAB Function ブロックの入力が負の場合、診断ビューアーにハイパーリンク付きのカスタム メッセージが表示されます。

    Diagnostic Viewer window displaying the custom error message with hyperlink.

参考

ツール

トピック