주요 콘텐츠

이 페이지는 기계 번역을 사용하여 번역되었습니다. 영어 원문을 보려면 여기를 클릭하십시오.

블록 어노테이션에서 사용자 지정 주석 생성

R2026b

이 예제는 블록에 연결된 어노테이션을 생성 코드의 주석으로 렌더링하는 방법을 보여줍니다.

블록 설명과 비교하여 어노테이션은 다음과 같은 장점을 제공합니다:

  • 어노테이션은 Simulink® 캔버스에 표시되며, 이곳에서 직접 생성, 확인 및 편집할 수 있습니다.

  • 어노테이션을 여러 블록에 연결할 수 있습니다. 또한 여러 어노테이션을 하나의 블록에 연결할 수도 있습니다.

  • 어노테이션에 수식과 테이블을 삽입한 다음 코드 주석으로 표시할 수 있습니다.

Simulink 모델의 어노테이션 검사

예제 모델을 엽니다.

model = 'CustomCodeComments';
open_system(model)

이 모델에는 블록에 연결된 두 개의 어노테이션이 포함되어 있습니다:

어노테이션을 블록에 연결하는 방법은 주석을 블록 및 영역과 연결하기를 참조하십시오.

screenshot3.png

어노테이션을 주석으로 삽입하기

1. 구성 파라미터 대화 상자를 엽니다. 코드 생성 창에서 시스템 타깃 파일 파라미터를 ert.tlc로 설정하십시오.

set_param(model,SystemTargetFile='ert.tlc');

2. 주석 창에서 블록 주석에 연결된 어노테이션 파라미터를 선택합니다.

set_param(model,AnnotationsInComments='on');

3. 모델을 빌드하고 코드를 생성합니다.

slbuild(model);
### Searching for referenced models in model 'CustomCodeComments'.
### Total of 1 models to build.
### Starting top model code generation target build for: CustomCodeComments
### Successful completion of build procedure for: CustomCodeComments

Build Summary

Top model targets:

Model               Build Reason                                  Status                        Build Duration
==============================================================================================================
CustomCodeComments  Target (CustomCodeComments.c) did not exist.  Code generated and compiled.  0h 0m 13.773s

1 of 1 models built (0 models already up to date)
Build duration: 0h 0m 14.627s

코드 생성기는 사용자의 어노테이션을 코드 내의 주석으로 변환합니다.

cfile = fullfile('CustomCodeComments_ert_rtw','CustomCodeComments.c');
coder.example.extractLines(cfile,"Product: '<Root>/Product' incorporates:", 'Gateway: Stateflow', 1, 0);
  /* Product: '<Root>/Product' incorporates:
   *  Constant: '<Root>/Constant'
   *  Inport: '<Root>/In1'
   *  Inport: '<Root>/In2'
   *  Inport: '<Root>/In3'
   *  Inport: '<Root>/In4'
   *
   * Block description for '<Root>/Product':
   *  This block determines the output index by taking the inner product of
   *  the vector of inputs and [1 2 3 4].
   *
   * Annotations for '<Root>/Product':
   *  $C_{ij} = \sum_k A_{ik} B_{kj}$
   *  This annotation is shared
   *
   *
   * Annotations for '<Root>/Constant':
   *  This annotation is shared
   */
  indexed_data = ((rtU.In1 * const_val[0] + rtU.In2 * const_val[1]) + rtU.In3 *
                  const_val[2]) + rtU.In4 * const_val[3];

  /* Chart: '<Root>/Stateflow'
   *
   * Block description for '<Root>/Stateflow':
   *  Stateflow block decides the index output by following logic
   *  1. If one and only one input signal is enabled, the index will
   *  refer to the enabled signal line.
   *  2. Otherwise, maintain the old value.
   *
   * Annotations for '<Root>/Stateflow':
   *  This annotation is shared
   */

블록에 여러 개의 어노테이션이 있는 경우, 코드 생성기는 각 어노테이션을 별도의 줄에 배치합니다. 수식이 포함된 경우, 코드 생성기는 해당 수식을 구성하는 기본 MathML 또는 LaTeX 코드를 렌더링합니다. 마지막으로, 어노테이션 주석은 블록 설명 주석과 함께 표시된다는 점에 유의하십시오.

제한 사항

다음 어노테이션은 생성 코드에서 주석으로 표시되지 않습니다:

  • 영역 어노테이션을 포함하여 모델 요소와 연결되지 않은 어노테이션

  • 축소된 블록에 첨부된 어노테이션

다음과 같은 어노테이션 요소는 주석에 표시되지 않습니다:

  • 영상

  • 굵게, 밑줄, 기울임꼴 등을 포함한 텍스트 서식 지정

어노테이션과 여기에 연결된 코드 주석 간에는 직접 추적할 수 없습니다. 하지만, 어노테이션이 연결된 블록과 해당 코드 주석 간에는 추적할 수 있습니다. 모델-코드 추적성에 대한 자세한 내용은 생성 코드에서 Simulink 모델 요소 추적하기를 참조하십시오.

참고 항목

도움말 항목