文档

万博1manbetx编辑or

This example shows the basics of how to create a model, add blocks to it, connect blocks, and simulate the model. You also learn how to organize your model with subsystems, name parts of a model, and modify a model.

开始万博1manbetx并创建模型

  1. 在Simuli万博1manbetxnk中®开始Page, click theBlank Modeltemplate.

    A new model based on the template opens in the Simulink Editor.

  2. Open the Library Browser so that you can access the blocks you need to add to your model. In the Simulink Editor, click theLibrary Browserbutton

添加Blocks to the Model

A minimal model takes an input signal, operates on it, and outputs the result. In the Library Browser, the Sources library contains blocks that represent input signals. The Sinks library has blocks that you can use to capture and display outputs. The other libraries contain blocks you can use for a variety of purposes, such as math operations.

In this basic model, the input is a sine wave, the operation is a gain (which increases the signal value by multiplying), and you output the result to a scope. Try different techniques to explore the library and to add blocks to your model.

添加时,编辑器名称会阻止它们。例如,它名称第一个Gain阻止您添加增益,下一个增益1等。默认情况下,Simulink编辑万博1manbetx器隐藏了这些名称。但是,您可以通过选择块来查看名称。您也可以明确命名一个块,以便出现名称。您可以通过选择编辑器给出的所有名称展示and clearing theHide Automatic Names复选框。有关显示块名称的更多信息,请参阅Manage Block Names

  1. 打开来源库。在库浏览器的树视图中,单击Sourceslibrary.

  2. In the right pane, hover over the正弦波block to see a tooltip describing its purpose.

  3. 添加a block to your model using a context menu. Right-click the正弦波block and select添加block to model untitled。(To learn more about the block, selectHelpfrom the context menu.)

  4. 添加a block to your model by dragging. In the library tree view, clickMath Operations。In the Math Operations library, locate theGainblock and drag it to your model to the right of the Sine Wave block.

  5. In the library tree view, click万博1manbetx视图的子程序库图标正确的锅e. This view is an alternative way to navigate the library structure. Double-click theSinkslibrary icon.

  6. 在水槽库中,找到Scope阻止并使用上下文菜单或拖动它将其添加到您的模型中。

    该图显示了您到目前为止的模型。

Align and Connect Blocks

Connect the blocks to create the relationships between model elements needed to make the model operate. Reading the model is easier when you line up the blocks according to how they interact with each other. Shortcuts help you to align and connect the blocks.

  1. Drag the Gain block so it lines up with the Sine Wave block. An alignment guide appears when the blocks line up horizontally. Release the block, and a blue arrow appears as a preview of the suggested connection. The block name appears while the block is selected.

  2. To make the connection, click the end of the arrow. A solid line appears in place of the guide.

  3. 对齐并使用相同的技术将示波器块连接到增益块。

    小费

    使用Diagram>Arrangemenu for additional alignment options.

Set Block Parameters

You can set parameters on most blocks. Parameters help you to specify how a block operates in your model. You can use the default values or you can set values as needed. Use the Property Inspector to set parameters. Alternatively, you can double-click most blocks to set the parameters using a block dialog box. To understand when to use each approach, seeSetting Properties and Parameters

In your model, set the sine wave amplitude and the gain value.

  1. 显示属性检查器。选择View>Property Inspector

  2. 选择the正弦波堵塞。

  3. 在物业检查员中,设置Amplitude参数为2

  4. 选择theGain阻止并设置Gain参数为3。该值出现在块上。

添加更多块

Suppose that you want to perform another gain but on the absolute value of the output from the正弦波堵塞。添加blocks for this purpose, trying different techniques for locating blocks in the library and adding them to your model.

  1. If you know the name of the block that you want to add, you can use a shortcut. Double-click where you want to add the block, and type the block name, in this case Gain. A list of possible blocks appears.

  2. Click the block name or, with the block name highlighted, pressEnter。您可以使用箭头键突出显示块名,如果它不在列表中。

  3. 一些块显示了一个提示,您可以输入其中一个块参数的值。这Gainblock prompts you to enter theGainvalue. Type3and pressEnter

  4. To get an absolute value, add an腹肌堵塞。Suppose you do not know the library a block is in or the full name of the block. You can search for it using the search box in the Library Browser. Enter腹肌in the search box and pressEnter。When you find the Abs block, add it to the left of the new Gain block.

  5. 添加another Scope block. You can right-click the existing Scope block and drag to create the copy or use theCopyandPaste命令。

    该图显示了模型的当前状态。

分支A连接

这input to the second Gain block is the absolute value of the output from the Sine Wave block. To use a single正弦波block as the input to both gain operations, create a branch from the正弦波block output signal.

  1. 对于模型中的第一组块,您使用水平对齐指南来帮助您对齐和连接它们。您也可以使用指南垂直对齐块。拖动第二个示波器块,使其在第一个范围内对齐。当垂直对准指南显示块是对齐的时,请释放它。

  2. You can click two ports to connect them. After you click the first port, compatible ports appear highlighted. Click the second port to connect.

    Align and connect the blocks as shown.

  3. 创建一个从正弦波块输出到ABS块的分支。单击ABS块的输入端口。模型中的兼容端口显得突出显示。将光标从正弦波块向输出信号线移动。出现预览行。单击以创建分支。

    Alternatively, you can start the branch by clicking the line segment and then moving the cursor toward the port.

  4. 名称信号。双击较低增益块和范围块之间的信号和键入Scope。Double-click the line and not a blank area of the canvas. For other techniques that you can use with signal names, see信号名称和标签动作

Try these methods to add or connect blocks:

  • Drag from a block port and release so that a red, dotted line appears. Double-click the end of the line to use the block insertion shortcut. Suggested blocks for the current context appear on the menu. You can select one of the listed blocks or start typing to search for any block in the library.

    To improve the menu suggestions based on your model designs, seeImprove Quick Block Insert Results

  • After you click a port, hold转移as you connect to another port. Holding转移将您置于您可以建立多个连续连接的模式。例如,握住转移,,,,you can branch a new signal line and connect it to another port or signal line with one click.

  • 选择the first block andCtrl+单击块你想连接。这个technique is useful when you want to connect blocks that have multiple inputs and outputs, such as multiple blocks to a bus or two subsystems with multiple ports. As with clicking two ports, this technique is useful when you do not want to align blocks. The signal line bends as needed to make the connection.

    To approximate a diagonal line from line segments, press转移and drag a vertex.

小费

To improve the shape of a signal line, select the line and, from the ellipsis menu, selectAutoroute Line。这line redraws if a better route between model elements is possible. You can select自动路线线从“省略号”菜单中,选择单个块或通过拖动选择框选择的多个模型元素来改进线路。

Organize Your Model

You can group blocks in subsystems and label blocks, subsystems, and signals. For more information about subsystems, see创建一个子系统

  1. Drag a selection box around the Abs block and the Gain block next to it.

  2. Move the cursor over the ellipses that appear at the corner of the box where you ended the selection. From the ellipsis menu, select创建子系统

    A subsystem block appears in the model in place of the selected blocks.

    To resize the subsystem block for the best fit in your model, drag the block handles.

  3. 给子系统一个有意义的名称。选择块,双击名称,然后键入腹肌olute Value。Naming a block causes the name to appear in the model.

  4. Open the Absolute Value subsystem by double-clicking it.

    小费

    To use the Explorer Bar to navigate the model hierarchy, right-click the subsystem and selectOpen in New Tab

    子系统包含您选择为子系统基础的块和信号。它们连接到两个新块:一个机场块和一个外口块。Inport和Outport块对应于子系统上的输入和输出端口。从包含命名信号的选择中创建子系统将信号的名称添加到相应的Inport或Outport。

  5. Click theUp to Parentbuttonto return to the top level of the model.

  6. 该图在创建子系统并将其命名之后显示了该模型。

Simulate Model and View Results

  1. You can simulate a model using theSimulation>命令 (Ctrl+T) or thebutton。Simulate the model using the technique that you prefer.

    在此示例中,仿真运行10秒钟,即默认设置。

  2. 双击两个范围块以打开它们并查看结果。

    该图显示了两个结果。在第二个图中,正如预期的那样,正弦波的绝对值始终为正。

Modify the Model

You can add blocks to a signal, remove blocks from models, and redraw connections. To modify this model, add a bias to the input to both branches of your model. Also, replace one of the scopes with a different sink. Add more blocks to the subsystem and another output.

对于某些块,将线路连接到它会添加输入端口或输出端口。例如,当您将行连接到该线路时,端口出现在子系统上。添加端口的其他块包括Bus Creator,,,,Scope,,,,and添加,,,,,,,,and产品块。有关更多信息,请参阅Automatic Port Creation: Add inports and outports to blocks when routing signals

  1. 添加aBiasblock to the model and set theBias参数为2

  2. Drag the block onto the signal line after the Sine Wave block but before the branch. If you need to make room for the block, drag the Sine Wave block to the left or move the end of the branch by dragging it to the right.

    当您将块拖到信号线上时,块在两端连接到信号线。当您对该位置感到满意时,释放块。

  3. Remove the top Scope block. Press转移and drag the block if you want to disconnect it from the model but do not want to delete it. Cut or delete it using the编辑menu commands or a keystroke. The broken connection appears as a red dotted line.

    小费

    When you delete a block that has one input and one output, a prompt appears between the broken connection lines. Click the prompt to connect the signals.

  4. 添加aTo Workspace在断开连接末端的模型挡住。这To Workspaceblock outputs the results to a variable in the MATLAB workspace.

  5. 添加a正弦波阻止模型并将振幅设置为5。Place it to the left of the subsystem.

  6. 添加another input to the subsystem. Drag a line from the new正弦波block to the left side of the subsystem. A new port, In2, appears on the subsystem.

  7. 添加an output to the subsystem. Add anotherTo Workspaceblock to the model and place it to the right of the subsystem. Drag a line from its input port to the right side of the subsystem. A new port, Out2, appears on the subsystem.

  8. Open the subsystem and rename the Out2 block Workspace. Add aManual Switchblock to the subsystem. Resize it and connect it as shown. Branch the signal after the Gain block to direct the output to theTo Workspace堵塞。

    这n, return to the top level of the model. The figure shows the current model.

  9. 模拟模型。

    • simoutandsimout1variables appear in the MATLAB workspace. Double-click each variable to explore the results.

    • 如果要使用第二个正弦波作为子系统算法的输入,请打开子系统并双击开关。输入更改为in2。再次模拟。

    小费

    To toggle between simulating the model with and without the effects of theBias块,右键单击Biasblock and selectComment Through。这block stays in the model but does not affect the operation. Right-click theBiasblock and selectUncommentto enable the block. TheComment Out命令注释块的输出信号,因此信号数据不会通过。尝试这些命令中的每一个以更好地理解它们的效果。

Related Topics

Was this topic helpful?