Documentation

添加全球评论

The following examples show how to add a global comment to a Simulink®model so that the comment text appears in the generated file or files where you want. Specify a template symbol name with a SimulinkDocBlock, a Simulink annotation, or a Stateflow®note. You can also use a sorted-notes capability that works with Simulink annotations or Stateflow notes (but notDocBlocks). For more information about template symbols, seeTemplate Symbols and Rules.

Note

Template symbol namesDescriptionandModifiedHistoryalso are fields in the Model Properties dialog box. If you use one of these symbol names for global comment text, and its Model Properties field also has text in it, both names appear in the generated files.

Use a金宝appDocBlock to Add a Comment

  1. With the model open, from theViewmenu, selectLibrary Browser.

  2. Drag theDocBlockfromModel-Wide Utilitiesin the Simulink library into the model.

  3. Double-click theDocBlockand type the comment that you want in the editor. Save and close the editor.

  4. Right-click theDocBlockand selectMask > Mask Parameters.

  5. In theCode generation template symbolbox, type one of the following:

    • Abstract

    • Description

    • History

    • ModifiedHistory

    • Notes

    ClickOK. Template symbol names are case sensitive.

    If you are using aDocBlockto add comments to your code, set theDocument typetoText. If you setDocument typetoRTForHTML, your comments will not appear in the code.

  6. In the Block Properties dialog box, on theBlock Annotationtab, select%and clickOK. The symbol name that you typed in the previous step now appears under theDocBlockin the model.

  7. Save the model. After you generate code, the code generator places the comment in each generated file whose template has the symbol name that you typed. The code generator places the comment in the generated file at the location that corresponds to where the symbol name is located in the template file.

  8. To add more comments to the generated files, repeat steps 1–7.

Use a金宝appAnnotation to Add a Comment

  1. Double-click the unoccupied area on the model where you want to place the comment. SeeDescribe Models Using Annotations(Simulink).

  2. Typefollowed by the comment.Symbol_nameis one of the following:

    • Abstract

    • Description

    • History

    • ModifiedHistory

    • Notes

    For example, typeThis is the description I want. Template symbol names are case sensitive. (The"S"before the colon indicates "symbol.") If you want the code generator to sort multiple comments for theNotessymbol name, replace the next step withUse Sorted Notes to Add Comments.

  3. Click outside the rectangle and save the model. After you generate code, the code generator places the comment in each generated file whose template has the symbol name that you typed. The code generator places the comment in the generated file at the location that corresponds to where the symbol name is located in the template file. If you want the code generator to sort multiple comments for theNotessymbol name, replace the next step withUse Sorted Notes to Add Comments.

  4. To add one or more other comments to the generated files, repeat steps 1–3.

Use aStateflowNote to Add a Comment

  1. Right-click the unoccupied area on the Stateflow chart where you want to place the comment.

  2. Select the annotation icon from the palette.

  3. Typefollowed by the comment.Symbol_nameis one of the following:

    • Abstract

    • Description

    • History

    • ModifiedHistory

    • Notes

    For example, typeThis is the description I want. Template symbol names are case sensitive. If you want the code generator to sort multiple comments for theNotessymbol name, replace the next step withUse Sorted Notes to Add Comments.

  4. Click outside the note and save the model. After you generate code, the code generator places the comment in each generated file whose template has the symbol name that you typed. The code generator places the comment in the generated file at the location that corresponds to where the symbol name is located in the template file.

  5. To add one or more other comments to the generated files, repeat steps 1–4.

Use Sorted Notes to Add Comments

The sorted-notes capability allows you to add automatically sorted comments to the generated files. The code generator places these comments in each generated file at the location that corresponds to where theNotessymbol is located in the template file.

The code generator uses the following sorting order:

  • Numbers before letters.

  • Among numbers, 0 is first.

  • Among letters, uppercase are before lowercase.

You can use sorted notes with a Simulink annotation or a Stateflow note, but not with aDocBlock.

  • In the Simulink annotation or the Stateflow note, typefollowed by the first comment.Yis a number or a letter.

  • Repeat for as many additional comments you want. ReplaceYwith a subsequent number or letter.

The figure illustrates sorted notes on a model, and where the code generator places each note in a generated file.

The relevant fragment from the generated file for this model is:

** NOTES ** Note1: This is the first comment I want associated with the Notes symbol. Note2: This is the second comment I want under Notes. Noteb: This is the third comment. **
Was this topic helpful?