Main Content

编写 MATLAB 函数的需求

需求用于描述设计必须满足的行为。需求通常采用自然语言语句、公式、表格和图的形式。在 Requirements Toolbox™ 中,您可以使用需求编辑器来编写需求以及创建包含需求的需求集。

在本教程的这一步,您将编写用于描述将两个数字相加的 MATLAB® 函数所需行为的需求。

描述所需行为

在此示例中,该函数的功能行为必须满足以下需求:

  • The function shall take two numerical inputs.

  • The function shall add the two inputs.

  • The function shall output the result of the addition.

此外,该函数必须检查输入:

  • The function shall not allow inputs of Inf or NaN.

在需求编辑器中编写需求

在 Requirements Toolbox 中使用需求编辑器编写需求。首先,打开 MyAdd 工程,以便可以在该工程中保存需求集。

openProject("MyAdd");

打开需求编辑器。在 App 选项卡的验证、确认和测试下,点击需求编辑器

点击新建需求集创建一个新的需求集。将需求集命名为 myAddReqs,然后将需求集保存在 MyAdd 工程的 documents 文件夹中。

The Requirements Editor shows the myAddReqs requirement set, which has no requirements.

选择需求集并点击添加需求,以向需求集添加需求。在右窗格中,使用需求中的文本向摘要属性和描述属性添加信息:

  • 摘要:Take two inputs

  • 描述:The function shall take two numerical inputs.

摘要属性是用于标识需求的简短短语。描述属性包含有关所需行为的详细信息。

Requirement 1 in the myAddReqs requirement set is selected in the Requirements Editor and its Summary and Description properties are shown.

使用以下摘要和描述添加第二个需求:

  • 摘要:Add the inputs

  • 描述:The function shall add the two inputs.

使用以下摘要和描述添加第三个需求:

  • 摘要:Output the result

  • 描述:The function shall output the result of the addition.

使用以下摘要和描述添加第四个需求:

  • 摘要:Inputs should be finite

  • 描述:The function shall not allow inputs of Inf or NaN.

The myAddReqs requirement set and its four requirements and requirement summaries are shown as they appear in the Requirements Editor.

点击保存来保存对需求集的更改。

另请参阅

App