simulink入门教程
Simulink入门指南

3 Creating a Simulink Model•“Overview of a Simple Model”on page3-2•“Creating the Simple Model”on page3-3•“Connecting Blocks in the Simple Model”on page3-9•“Simulating the Simple Model”on page3-143Creating a Simulink®ModelOverview of a Simple ModelYou can use Simulink software to model dynamic systems and simulate thebehavior of the models.The basic techniques you use to create a simple modelare the same techniques you will use for more complex models.To create this simple model,you need four blocks:•Sine Wave—Generates an input signal for the model.•Integrator—Processes the input signal.•Mux—Multiplexes the input signal and processed signal into a singlesignal.•Scope—Visualizes the signals in the model.After connecting the blocks,they model a system that integrates a sine wavesignal and displays the result along with the original signal.You can build this simple model yourself,starting with“Creating a NewModel”on page3-3.3-2Creating the Simple ModelCreating the Simple ModelIn this section...“Creating a New Model”on page3-3“Adding Blocks to a Model”on page3-4“Moving Blocks in the Model”on page3-8Creating a New ModelBefore creating a model,you need to start Simulink,and then open an emptymodel window.1If Simulink is not running,in the MATLAB Command Window,entersimulinkThe Simulink Library Browser opens.2From the Simulink Library Browser menu,select File>New>Model.A Simulink editor window opens with an empty model in the right pane.3-33Creating a Simulink®Model3Select File>Save as.The Save As dialog box opens.4In the File name box,enter a name for your model,and then click Save.For example,enter simple_model.The software saves your model with the filename simple_model.mdl.Adding Blocks to a ModelTo create a model,you begin by copying blocks from the Simulink LibraryBrowser to the Simulink editor window.For a description of the blocks in thisexample,see“Overview of a Simple Model”on page3-2.1In the Simulink Library Browser,select the Sources library.The Simulink Library Browser displays blocks from the Sources library inthe right pane.3-4Creating the Simple Model3-53Creating a Simulink®Model2Select the Sine Wave block,and then drag it to the editor window.A copy of the Sine Wave block appears in your model.3Add the following blocks to your model in the same way you added theSign Wave block.Library BlockSinks ScopeContinuous IntegratorSignal Routing MuxYour model now has the blocks you need for the simple model.3-6Creating the Simple Model3-73Creating a Simulink®ModelMoving Blocks in the ModelBefore you connect the blocks in your model,you should arrange themlogically to make the signal connections as straightforward as possible.Tomove a block in a model,you can either•Click and drag the block•Select the block,and then press the arrow keys on the keyboard1Move the Scope block after the Mux block output.2Move the Sine Wave and Integrator blocks before the Mux block Inputs.Your model should look similar to the following figure.Your next task is to connect the blocks together with signal lines.See“Connecting Blocks in the Simple Model”on page3-9.3-8Connecting Blocks in the Simple ModelConnecting Blocks in the Simple ModelIn this section...“Block Connections in a Model”on page3-9“Drawing Lines Between Blocks”on page3-9“Drawing a Branch Line”on page3-12Block Connections in a ModelAfter you add blocks to your model,you need to connect them.The connectinglines represent the signals within a model.Most blocks have angle brackets on one or both sides.These angle bracketsrepresent input and output ports:•The>symbol pointing into a block is an input port.•The>symbol pointing out of a block is an output port.Input port Output portDrawing Lines Between BlocksConnect the blocks by drawing lines between output ports and input ports.For how to add blocks to the model in this example,see“Adding Blocks toa Model”on page3-4.1Position your mouse pointer over the output port on the right side of theSine Wave block.3-93Creating a Simulink®Model2Drag a line from the output port to the top input port of the Mux block.While holding the mouse button down,the connecting line is shown as alight colored arrow.3Release the mouse button over the output port.Simulink connects the blocks with an arrow indicating the direction ofsignal flow.4Drag a line from the output port of the Integrator block to the bottom inputport on the Mux block.The Integrator block connects to the Mux block with a signal line.3-10Connecting Blocks in the Simple Model5Select the Mux block,hold down the Shift key,and then select the Scopeblock.A line is drawn between the blocks to connect them.Note The Shift+click shortcut is useful when you are connecting widelyseparated blocks,or when working with complex models.Your model should now look similar to the following figure.3-113Creating a Simulink®ModelDrawing a Branch LineThe simple model is almost complete,but one connection is missing.To finishthe model,you need to connect the Sine Wave block to the Integrator block.This final connection is somewhat different from the other three connections,which all connect output ports to input ports.Because the output port of theSine Wave block already has a connection,you must connect this existing lineto the input port of the Integrator block.The new line,called a branch line,carries the same signal that passes from the Sine Wave block to the Mux block.1Position the mouse pointer on the line between the Sine Wave and theMux block.2Hold down the Ctrl key,and then drag a line to the input port of theIntegrator block input port.This step adds a connection to the existing line and draws a line betweenthe connection and the input port of the Integrator block.3-12Connecting Blocks in the Simple Model3From the File menu,click Save.Your model is now complete.It should look similar to the following figure.After your model is complete,you can simulate the model.See“Simulatingthe Simple Model”on page3-14.3-133Creating a Simulink®ModelSimulating the Simple ModelIn this section...“Setting Simulation Options”on page3-14“Running a Simulation and Observing Results”on page3-15Setting Simulation OptionsBefore you simulate a model,you have to set simulation options.You specifyoptions,such as the stop time and solver,using the Model ConfigurationParameters dialog box.For how to build the model in this example,see“Creating the Simple Model”on page3-3.1In the Simulink editor window,select Simulation>ModelConfiguration Parameters.The Configuration Parameters dialog boxopens to the Solver pane.2In the Stop time field,enter20,and in the Max step size field,enter0.2.3Click OK.The software updates the parameter values with your changes and closesthe Configuration Parameters dialog box.For more information about Simulink configuration parameters,see“Configuration Parameters Dialog Box”.3-14Simulating the Simple Model Running a Simulation and Observing ResultsAfter entering your configuration parameter changes,you are ready tosimulate the simple model and visualize the simulation results.1In the Simulink editor window and from the menu,selectSimulation>Start.The simulation runs,and then stops when it reaches the stop time specifiedin the Model Configuration Parameters dialog box.Tip Alternatively,you can control a simulation by clicking the Startsimulation button and Stop simulation button on the editorwindow toolbar.2Double-click the Scope block.The Scope window opens and displays the simulation results.The plotshows a sine wave signal with the resulting cosine wave signal from theIntegrator block.3-153Creating a Simulink®Model3From the toolbar,click the Parameters button,and then the Graphicstab.The Scope Parameters dialog opens with figure editing commands.4Make changes to the appearance of the figure.For example,select whitefor the Figure and Axes background color,and change the signal line colorsto blue and green.Click the Apply button to see your changes.3-16Simulating the Simple Model5Select File>Close.The Simulink editor window closes with changes to your model and the configuration parameters.3-173Creating a Simulink®Model 3-184 Modeling a Dynamic Control System•“Understanding a Demo Model”on page4-2•“Simulating the Demo Model”on page4-11•“Moving Data Between MATLAB and the Demo Model”on page4-194Modeling a Dynamic Control SystemUnderstanding a Demo ModelIn this section...“Overview of the Demo Model”on page4-2“Opening the Demo Model”on page4-3“Anatomy of the Demo Model”on page4-4“Subsystems in the Demo Model”on page4-5“Subsystems and Masks”on page4-9“Creating a Subsystem”on page4-9“Creating a Subsystem Mask”on page4-10Overview of the Demo ModelThis demo model illustrates how you can use Simulink software to modela dynamic control system.The model defines a heating system and thethermodynamics of a house.It included the outdoor environment,the thermalcharacteristics of a house,and the house heating system.Use this model to explore common Simulink modeling tasks,such as•Grouping multiple blocks into a single subsystem block to simplify a blockdiagram.See“Subsystems in the Demo Model”on page4-5•Customizing the appearance of blocks using the masking feature.See“Creating a Subsystem Mask”on page4-10•Simulating a model and observing the results using a Scope block.See“Running the Simulation”on page4-11•Changing the input parameters of the model to investigate how the systemresponds.See“Changing the Thermostat Setting”on page4-12.•Importing data from the MATLAB workspace into a model beforesimulation.See“Importing Data from the MATLAB Workspace”on page4-19.•Exporting simulation data from the model back to the MATLAB workspace.See“Exporting Simulation Data to the MATLAB Workspace”on page4-23. 4-2Understanding a Demo Model Opening the Demo ModelThe demo model for this example is called sldemo_househeat.It models the heating system and thermodynamics of a house.1Start MATLAB,and then In the MATLAB Command Window,enter sldemo_househeatThe Simulink editor opens with the demo model.4Modeling a Dynamic Control SystemAnatomy of the Demo ModelThe demo model defines the dynamics of the outdoor environment,thethermal characteristics of the house,and the house heating system.It allowsyou to simulate how the thermostat setting and outdoor environment affectthe indoor temperature and cumulative heating costs.The demo model includes many of the same blocks you used to create thesimple model in Chapter3,“Creating a Simulink Model”.These include:•A Scope block(labeled PlotResults)on the far right,displays thesimulation results.•A Mux block at the bottom right,combines the indoor and outdoortemperature signals for the Scope.•A Sine Wave block(labeled Daily Temp Variation)at the bottom left,provides one of three data sources for the model.In the demo model,the thermostat is set to70degrees Fahrenheit.Thesystem models fluctuations in outdoor temperature by applying a sine wavewith amplitude of15degrees to a base temperature of50degrees.The three data inputs(sources)are provided by two Constant blocks(labeledSet Point and Avg Outdoor Temp),and the Sine Wave block(labeled DailyTemp Variation).The Scope block labeled PlotResults is the one output(sink).Understanding a Demo Model Subsystems in the Demo ModelThe sldemo_househeat demo model uses subsystems to simplify theappearance of the block diagram,create reusable components,and customizethe appearance of blocks.A subsystem is a hierarchical grouping of blocks encapsulated by a single Subsystem block.The demo model uses the following subsystems:Thermostat,Heater,House, Fahrenheit to Celsius,and Celsius to Fahrenheit1In the MATLAB Command Window,entersldemo_househeatThe demo model opens in the Simulink editor window.4Modeling a Dynamic Control System2Subsystems can be complex and contain many blocks that might otherwiseclutter a diagram.For example,double-click the House subsystem block toopen it.Contents of House subsystemThe subsystem receives heat flow and external temperature as inputs,which it uses to compute the current room temperature.You could leaveeach of these blocks in the main model window,but combining them as asubsystem helps simplify the block diagram.Understanding a Demo Model3A subsystems can also be simple and contain only a few blocks.Forexample,double-click the Thermostat subsystem block to open it.Contents of Thermostat subsystemThis subsystem models the operation of a thermostat,determining whenthe heating system is on or off.It contains only one Relay block,butlogically represents the thermostat in the block diagram..4Modeling a Dynamic Control SystemUnderstanding a Demo Model Subsystems and MasksSubsystems allows you to group related blocks into one block.They are also reusable,enabling you to implement an algorithm once and use it multiple times.For example,the model contains two instances of identical subsystems named Fahrenheit to Celsius.These subsystems convert the inside and outside temperatures from degrees Fahrenheit to degrees CelsiusYou can customize the appearance of a subsystem by using a process knownas masking.Masking a subsystem allows you to specify a unique icon anddialog box for the Subsystem block.For example,the House and Thermostat subsystems display custom icons that depict physical objects,while the conversion subsystems display custom dialog boxes when you double-clickthem.1Double-click the Fahrenheit to Celsius block.The custom dialog box for the F2C block opens.2To view the underlying blocks in the conversion subsystem,right-click thesubsystem block,point to Mask,and then select Look Under Mask.The editor displays the blocks behind the mask.Creating a SubsystemTo create a subsystem:1In the demo model window,select the set point and Fahrenheit to Celsiusblocks.4Modeling a Dynamic Control System2From the menu,select Diagram>Subsystem&Modeling Reference>Create Subsystem from Selection.The blocks are combined into one subsystem block.For more information about working with subsystems,see“CreatingSubsystems”in the Simulink User’s Guide.Creating a Subsystem MaskTo mask a subsystem:1In the demo model window,right-click the new subsystem block,and thenselect Mask>Add/Edit Mask.The Mask Editor dialog box opens.2From the Command list,select disp(show text in center of block).The dialog box displays the syntax for this command below the list.3In the Icon Drawing commands field,enter disp('SelectTemperature').4Click OK.The software masks the subsystem block with the text you entered.For more information about masking subsystems,see“Working with BlockMasks”in the Simulink User’s Guide.Simulating the Demo ModelSimulating the Demo ModelIn this section...“Running the Simulation”on page4-11“Changing the Thermostat Setting”on page4-12“Changing the Average outdoor Temperature”on page4-14“Changing the Daily Temperature Variation”on page4-16Running the SimulationSimulating the model allows you to observe how the thermostat setting andoutdoor environment affect the indoor temperature and the cumulativeheating cost.1In the demo model window,double-click the Scope block namedPlotResults.The software opens a Scope window that contains two axes with the labelsHeatCost and Temperatures.2From the menu,select Simulation>Start.The software simulates the model.As the simulation runs,the cumulativeheating cost appears on the HeatCost graph at the top of the Scope window.The indoor and outdoor temperatures appear on the Temperatures graphas yellow(top)and magenta(bottom)signals,respectively.4Modeling a Dynamic Control SystemChanging the Thermostat SettingOne of the most powerful benefits of modeling a system with Simulink isthe ability to interactively define the system inputs and observe changes inthe behavior of your model.This allows you to quickly evaluate your modeland validate the simulation results.Change the thermostat setting to68degrees Fahrenheit and observe howthe model responds.1In the Simulink editor window,double-click the Set Point block.TheSource Block Parameters dialog box opens.2In the Constant value field,enter68.Simulating the Demo Model3Click OK.The software applies your changes.4To rerun the simulation,select Simulation>Start.The software simulates the model.In the Scope window,notice that a lower thermostat setting reduces the cumulative heating cost.4Modeling a Dynamic Control SystemChanging the Average outdoor TemperatureChange the average outdoor temperature to45degrees Fahrenheit andobserve how the model responds.1In the Simulink editor window,double-click the Avg Outdoor Temp block.The Source Block Parameters dialog box opens.2In the Constant value field,enter45.Simulating the Demo Model3Click OK.The software applies your changes and closes the dialog box.4To rerun the simulation,select Simulation>Start.The software simulates the model dynamics.In the Scope window,noticethat a colder outdoor temperature increases the cumulative heating cost.4Modeling a Dynamic Control SystemChanging the Daily Temperature VariationDecrease the temperature variation to see how the model responds.1In the Simulink editor window,double-click the Daily Temp Variationblock.The Source Block Parameters dialog box opens.2In the Amplitude field,enter5.3Click OK.The software applies your changes and closes the dialog box.4To rerun the simulation,select Simulation>Start.The software simulates the model.In the Scope window,notice that amore stable outdoor temperature alters the frequency with which theheater operates.Simulating the Demo Model4Modeling a Dynamic Control SystemMoving Data Between MATLAB and the Demo ModelMoving Data Between MATLAB and the Demo ModelIn this section...“Importing Data from the MATLAB Workspace”on page4-19“Exporting Simulation Data to the MATLAB Workspace”on page4-23Importing Data from the MATLAB WorkspaceSimulink also allows you to import data from the MATLAB workspace to themodel input ports.This allows you to import actual physical data into yourmodel.For information about other data import capabilities,see“Importingand Exporting Simulation Data”in the Simulink User’s Guide.Note In this example,you will create a vector of temperature data inMATLAB,and use that data as an input to the Simulink model.To import data from the MATLAB workspace:1In the MATLAB Command Window,create time and temperature data byentering the following commands:x=(0:0.01:4*pi)';y=32+(5*sin(x));z=linspace(0,48,1257)';2In the Simulink editor window,select the Avg Outdoor Temp block,andthen press the Delete key to delete it.3Delete the following items from the model in the same way:•Daily Temp Variation block•Two input signal lines to the Sum block•Sum block4Modeling a Dynamic Control SystemThe model should now look similar to the following figure.Notice that theoutput signal from the Sum block changes to a red,dotted line,indicatingthat it is not connected to a block.4In the demo model window,select View>Library Browser.The Simulink Library Browser window opens.5In the Simulink Library Browser,select the Sources library.6From the Sources library right pane,select the In1block,and then drag itto the model window.Moving Data Between MATLAB and the Demo ModelAn In1block appears in the model window.7Connect the dotted line(originally connected to the Sum block)to the In1 block.8In the Simulink editor window,select Simulation>Configuration Parameters.The Configuration Parameters dialog box opens.9In the menu on the left side of the dialog,select Data Import/Export.The Data Import/Export pane opens.4Modeling a Dynamic Control System10Select the Input check box.11In the Input field,enter[z,y].12Click OK.The software applies your changes and closes the dialog box.13To rerun the simulation,select Simulation>Start.The software simulates the model.In the Scope window,notice that themodel ran using the imported data,showing colder temperatures andhigher heat use.Exporting Simulation Data to the MATLAB Workspace Once you have completed a model,you may want to export your simulation results to MATLAB workspace for further data analysis or visualization.For information about additional data export capabilities,see“Exporting Simulation Data”.To export the HeatCost data from the model to the MATLAB workspace:1In the Simulink Library Browser window,select the Sinks library.2From the Sinks library,select the Out1block,and then drag it to the top right of the demo model window.An Out1block appears in the model window.3Draw a branch line from the HeatCost signal line to the Out1block.For more information,see“Drawing a Branch Line”on page3-12.4Select Simulation>Configuration Parameters.The Configuration Parameters dialog box opens.5From the menu on the left side of the dialog box,select DataImport/Export.The Data Import/Export pane opens.6Select the Time and Output check boxes.7Click OK.The software applies your changes and closes the dialog box.8To rerun the simulation,select Simulation>Start.The software simulates the model and saves the time and HeatCost data to the MATLAB workspace.Notice that the tout and yout variables nowappear in the MATLAB workspace.。
Simulink动态系统仿真入门

Simulink动态系统仿真入门Simulink是基于MA TLAB的图形化仿真设计环境,是MATLAB 提供的进行动态系统建模、仿真和综合分析的集成软件包。
它使用图形化的系统模块对动态系统进行描述,并在此基础上采用MATLAB 的计算引擎对动态系统在时域内进行求解。
它可以处理的系统包括:线性、非线性、离散、连续及混合、单任务、多任务离散事件等。
在MATLAB7.X版本中,可以直接在Simulink环境中运作的工具箱和模型库很多,已经覆盖了航天、航空、通信、控制、信号处理等等诸多领域,涉及内容专业性很强。
1、Simulink系统的启动由于Simulink和MATLAB是高度集成在一起的,因此启动Simulink必须先启动MA TLAB。
在MA TLAB启动Simulink可以通过在命令窗口输入Simulink,或者点击MATLAB工具栏的Simulink 快速启动图标。
启动Simulink后,出现Simulink的主窗口,选择主菜单File中的New\model,即可以打开系统模型编辑器。
下图依次是MATLAB 主窗口、Simulink主窗口和系统模型编辑窗口,图中的箭头表示了操作顺序。
在打开一个新的系统模型文件以后,用户可以从Simulink模块库中选择适合的系统模块或自定义模块来建立系统模型。
我们通过一个简单的例子来分步说明Simulink建模和仿真的能力。
1)在MATLAB 窗口运行Simulink。
打开Simulink模块库浏览器。
2)点击Source子库前的“+”展开库,可以看到各种信源模块。
3)点击新建图标,打开一个空白型的模型窗口。
4)用鼠标选中需要的信源模块,把它拖入新建的空白模型编辑窗口,生成一个正弦波的复制品。
5)同样将信宿库Sinks中的示波器Scope拷贝到模型窗口。
6)利用鼠标完成两个模块的连线操作,完成一个简单的模型。
7)为进行仿真,双击示波器模块,打开示波器显示屏。
matlab-simulink初级教程

Simulink仿真环境基础学习Simulink是面向框图的仿真软件。
7.1演示一个Simulink的简单程序【例7.1】创建一个正弦信号的仿真模型。
步骤如下:(1) 在MATLAB的命令窗口运行simulink命令,或单击工具栏中的图标,就可以打开Simulink模块库浏览器(Simulink Library Browser) 窗口,如图7.1所示。
图7.1 Simulink界面(2) 单击工具栏上的图标或选择菜单“File”——“New”——“Model”,新建一个名为“untitled”的空白模型窗口。
(3) 在上图的右侧子模块窗口中,单击“Source”子模块库前的“+”(或双击Source),或者直接在左侧模块和工具箱栏单击Simulink下的Source子模块库,便可看到各种输入源模块。
(4) 用鼠标单击所需要的输入信号源模块“Sine Wave”(正弦信号),将其拖放到的空白模型窗口“untitled”,则“Sine Wave”模块就被添加到untitled窗口;也可以用鼠标选中“Sine Wave”模块,单击鼠标右键,在快捷菜单中选择“add to 'untitled'”命令,就可以将“Sine Wave”模块添加到untitled窗口,如图7.2所示。
(5) 用同样的方法打开接收模块库“Sinks”,选择其中的“Scope”模块(示波器)拖放到“untitled”窗口中。
(6) 在“untitled”窗口中,用鼠标指向“Sine Wave”右侧的输出端,当光标变为十字符时,按住鼠标拖向“Scope”模块的输入端,松开鼠标按键,就完成了两个模块间的信号线连接,一个简单模型已经建成。
如图7.3所示。
(7) 开始仿真,单击“untitled”模型窗口中“开始仿真”图标,或者选择菜单“Simulink”——“Start”,则仿真开始。
双击“Scope”模块出现示波器显示屏,可以看到黄色的正弦波形。
Simulink仿真操作基本教程

◼ 在 Simulink 模 型 或 模 块 库 窗
口内,用鼠标左键单击所需 模块图标,图标四角出现黑 色小方点,表明该模块已经 选中。
c) 模块拷贝及删除
◼ 在模块库中选中模块后,按 住鼠标左键不放并移动鼠标 至目标模型窗口指定位置, 释放鼠标即完成模块拷贝。
◼ 模块的删除只需选定删除的 模块,按Del键即可。
a) 启动Simulink。
➢ 单击MATLAB Command窗口工具条上的Simulink图标,或者
在MATLAB命令窗口输入simulink,即弹出图示的模块库窗 口界面(Simulink Library Browser)。该界面右边的窗口给出 Simulink所有的子模块库。
➢ 常用的子模块库有 Sources( 信 号 源 ) , Sink( 显 示输出),Continuous(线性连 续系统),Discrete(线性离 散系统),Function & Table (函数与表格),Math(数学 运算), Discontinuities (非 线性),Demo(演示)等。
图9-15 定步长算法
图9-16 变步长算法
第一章 Simulink动态仿真
① Solver页 ➢ Error Tolerance(误差限度): 算法的误差是指当前状态值与当前
状态估计值的差值,分为Relative tolerance(相对限度)和Absolute tolerance(绝对限度),通常可选auto。
第一章 Simulink动态仿真
a) 启动Simulink
① 用鼠标右键点击Simulink菜单项,则弹出一菜单条,点击该菜单
条即弹出该子库的标准模块窗口.如单击左图中的【Sinks】,出现 “Open the ‘Sinks’Library”菜单条,单击该菜单条,则弹出右图所 示的该子库的标准模块窗口。
Simulink基本操作

Simulink基本操作(2014.5 兰交大萌芽)Simulink是MATLAB软件所带的软件仿真工具。
其强大的功能几乎可以满足所有的系统仿真。
要掌握基本的仿真操作,必须认识仿真各个模块的英文名称。
其实记住图形是干嘛的即可。
说实话在运用外语软件时,英语真是个让人头疼的问题。
不过,得必须记住的是,在任务/现实面前,只能向前迈步。
下面我们介绍Simulink的基本操作,以截图为主。
一、1.打开MATLAB软件,点击Simulink按钮,进入Simulink仿真界面。
点击进入simulink2.新建*-mdl文件。
也可以打开已有的*-mdl文件进行编辑或仿真。
点击新建3.出现*-mdl界面。
现在进可以编辑机构框图了。
4.完成后,点击运行按钮,同时保存文件位置,注意文件地址要明确。
运行按钮Simulink给我们的基本模块结构很多,都在Simulink library browser窗口中。
其中有基本模块和专业模块。
常用基本模块。
二、下面,我们举例说明其简单的使用说明。
以下图为例。
该图为计算机控制系统的最少拍有纹波控制系统。
1.首先,添加各模块,同时修改其参数值,还可以边添加连线。
2.右键点击Add to …即可添加模块到*-mdl文件中。
点击右键点击我们可以改变其位置和大小。
3.再依次添加这两个。
发现在*-mdl文件中出现以下现象,不要着急!4.这时我们可以把他们移开(点击一个,拉开,再点击一个,拉开)同时放大合适的比例。
5.修改其属性的选中模块,双击打开。
比如Sum修改点击ok 得到6.双击Mux,在option中选择signals 点击ok,得连线鼠标放在箭头处,拉动,放入入口箭头处即可。
7.题目里出现两个相同模块的,可以进行复制、粘贴。
得到两个模块后在进行属性和参数的修改8.接着进行别的模块添加工作。
9.模块添加完成。
进行属性和参数设置,得到注;为了能让大家看的清楚些,我把布局缩小了,在自己实验仿真时,完全可以放开成大窗口,将模块放大,更清晰明了,不要小家子气。
Simulink入门教程

Simulink 快速入门要构建模型, 可以使用Simulink® Editor 和Library Browser。
启动 MATLAB 软件启动 Simulink 之前, 请先启动MATLAB®。
请参阅启动和关闭(MATLAB)。
配置 MATLAB 以启动 Simulink您在 MATLAB 会话中打开第一个模型时需要的时间比打开后续模型长, 因为默认情况下, MATLAB 会在打开第一个模型时启动 Simulink。
这种即时启动Simulink 的方法可以缩短 MATLAB 启动时间, 避免不必要的系统内存占用。
•要快速打开第一个模型, 您可以配置 MATLAB, 在它启动时同时启动Simulink。
要启动 Simulink 而不打开模型或 Library Browser, 请使用start_simulink。
•根据 MATLAB 的启动方式, 恰当使用此命令:•在 MATLAB startup.m文件中在操作系统命令行中, 使用matlab 命令和-r 开关例如, 要在运行Microsoft®Windows®操作系统的计算机上启动 MATLAB 时启动 Simulink, 请创建具有以下目标的桌面快捷方式:matlabroot\bin\win64\matlab.exe -r start_simulink在 Macintosh 和Linux®计算机上, 可在启动 MATLAB 时使用以下命令启动Simulink 软件:matlab -r start_simulink打开 Simulink Editor•要打开 Simulink Editor, 您可以:•创建一个模型。
在 MATLAB 的Home 选项卡上, 点击Simulink 并选择一个模型模板。
或者, 如果您已经打开了 Library Browser, 请点击New Model 按钮/。
有关创建模型的其他方法, 请参阅创建模型。
第1章SIMULINK入门

12.4.2 手动连接模块
• 1.从模块到模块的手动连接 • 当鼠标移动至输出模块的输出端口时,鼠标图标 将变成十字符型,此时按下鼠标左键,拖动鼠标 至目标模块输入端口,当鼠标图标由十字符型变 为双十字符型时,松开鼠标左键即可,如图所示。 • 2.从信号线某一点到模块的手动连接 • 将鼠标移动到信号线上某一点,此时鼠标图标变 为十字符型,其后的连接方式完全与从模块到模 块的连接相同。这种连接方式可以将一个信号传 递到多个模块,
12.4.4 操作模块名称
• 在SIMULINK模型中,每个模块都有自己唯一的模 块名。如果在同一系统中出现模块名的重复, SIMULINK将弹出一个Error对话框。 • 1.更改模块名称 • 2.移动模块名位置 • 3.显示或隐藏模块名
• 4.改变模块名的字体和大小
12.4.5 设置模块参数
12.1.2 SIMULINK启动
• 启动SIMULINK之前,首先要打开MATLAB,打开 MATLAB主界面,在命令窗口(Command Window) 输入命令simulink,回车即可启动SIMULINK,即 打开SIMULINK库浏览器(Simulink Library Browser)窗口,如图所示。
Constant
2{10} double [3x3] [3x3] 2{10}
Scope2
[3x3]
Constant1 Scope
double
3 Gain
double
Sine Wave
12.6 仿真设置
• 接下来将介绍SimulinkParameters对话框中基本 参数的设置方式。SimulinkParameters对话框中 仿真参数主要包括,解法器设置(Solver)、仿 真参数输入输出(Data Import/Export)、仿真 优化(Optimization)、仿真诊断 (Diagnostics)、仿真硬件实现(Hardware Implementation)、参考模型(Model Referencing) 和实时工作间(Real-time workshop)。在模型窗 口中选择菜单栏【Simulation/Configuration Parameter】,就可以打开Configuration Parameter(参数配置)对话框,
matlab之simulink最通俗教程

matlab之simulink最通俗教程Simulink是MATLAB的一个重要工具箱,用于建模和仿真控制系统。
Simulink提供了一种图形化建模环境,可以方便地构建复杂系统,并对其进行仿真和分析。
本文将详细介绍Simulink的基本原理和使用方法,以便初学者快速入门。
Simulink模型由各种模块组成,这些模块可以是系统组件、数学算法或信号处理函数。
用户可以使用Simulink库中的预定义模块,也可以自己编写MATLAB函数来创建自定义模块。
模块之间的连接通过信号线进行,可以传递各种类型的信号,如数值、布尔值和字符串。
使用Simulink建模的第一步是创建一个新模型。
在MATLAB命令窗口中输入“simulink”命令即可打开Simulink库浏览器。
然后,可以从左侧的“Simulink Library Browser”面板中拖动所需的模块到模型窗口中。
常用的模块包括输入输出模块、数学运算模块和逻辑控制模块。
在模型中添加模块后,可以使用鼠标将它们连接在一起。
要创建连接线,只需点击模块输出端口并将鼠标拖动到另一个模块的输入端口。
连接线将自动连接两个模块,形成信号传递路径。
连接线上可以添加箭头标记,用于指定信号的流动方向。
模型的参数和设置可以在模型窗口的右侧“Properties”面板中进行调整。
例如,可以设置模块的初始状态、仿真时间范围和采样时间。
还可以为模块添加注释、设置显示颜色和调整模块大小等。
Simulink提供了多种仿真和分析工具,用于评估模型的性能和行为。
可以使用“Simulate”按钮开始仿真并观察模型的实时响应。
仿真结果可以以图表或波形图的形式显示,并可以保存和导出到MATLAB工作空间中进行后续处理。
还可以使用模型验证和优化工具来检查模型的准确性和效率。
除了基本的建模和仿真功能外,Simulink还支持代码生成和硬件连接。
可以将Simulink模型转换为C代码,并嵌入到嵌入式系统中。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
S i m u l i n k入门教程-CAL-FENGHAI-(2020YEAR-YICAI)_JINGBIANSimulink?快速入门启动?Simulink?软件要构建模型,可以使用 Simulink??Editor 和 Library Browser。
启动?MATLAB?软件启动 Simulink 之前,请先启动 MATLAB?。
请参阅启动和关闭?(MATLAB)。
配置?MATLAB?以启动?Simulink您在 MATLAB 会话中打开第一个模型时需要的时间比打开后续模型长,因为默认情况下,MATLAB 会在打开第一个模型时启动 Simulink。
这种即时启动Simulink 的方法可以缩短 MATLAB 启动时间,避免不必要的系统内存占用。
要快速打开第一个模型,您可以配置 MATLAB,在它启动时同时启动 Simulink。
要启动 Simulink 而不打开模型或 Library Browser,请使用?start_simulink。
根据 MATLAB 的启动方式,恰当使用此命令:在 MATLAB?startup.m?文件中在操作系统命令行中,使用?matlab?命令和?-r?开关例如,要在运行 Microsoft??Windows??操作系统的计算机上启动 MATLAB 时启动Simulink,请创建具有以下目标的桌面快捷方式:matlabroot\bin\win64\matlab.exe -r start_simulink在 Macintosh 和?Linux??计算机上,可在启动 MATLAB 时使用以下命令启动Simulink 软件:matlab -r start_simulink打开?Simulink?Editor要打开 Simulink Editor,您可以:创建一个模型。
在 MATLAB 的?Home?选项卡上,点击?Simulink?并选择一个模型模板。
或者,如果您已经打开了 Library Browser,请点击?New Model?按钮?。
有关创建模型的其他方法,请参阅创建模型。
打开一个现有模型。
要打开最近使用的模型,请在 MATLAB?Home?选项卡上点击?Simulink。
或者,如果您知道要打开的模型的名称,可在 MATLAB 命令提示符下输入名称,例如?vdp。
有关打开模型的其他方法,请参阅打开模型。
提示Simulink Editor 会在 MATLAB 桌面的前端打开。
要将 MATLAB 桌面移动到前端,请在 Simulink Editor 中选择?View?>?MATLAB Desktop。
打开 Library Browser通过以下方式之一从 MATLAB 中打开 Simulink Library Browser:在主页选项卡上,点击?Simulink?并选择一个模型模板。
在新模型中,点击?Library Browser?按钮?。
在命令提示符下,输入?slLibraryBrowser。
Library Browser 随即打开,并显示您系统中的 Simulink 模块库的树视图。
当您点击树视图中的库时,右侧窗格将显示库的内容。
注意除了 Simulink 库之外,Simulink 还附带了模块库。
这些库支持对附带的示例模型(包含这些库中的模块)进行仿真。
但是,要生成代码或修改这些模块,必须拥有相关的产品许可证。
在?Simulink?Editor 中构建和编辑模型启动?Simulink?并创建一个新模型向模型中添加模块对齐和连接模块设置模块参数添加更多模块建立分支连接组织模型对模型进行仿真并查看结果修改模型本示例介绍创建模型、向模型中添加模块、连接模块以及仿真模型的基础知识。
您还将学习如何使用子系统组织模型、为模型的组件命名以及修改模型。
启动?Simulink?并创建一个新模型1.在 MATLAB??主页选项卡中,点击?Simulink。
2.在 Simulink??Start Page 上,点击?Blank Model?模板。
将在 Simulink Editor 中打开一个基于?Blank Model?模板的新模型。
3.打开 Library Browser,以访问创建模型需要的模块。
在 Simulink Editor中,点击?Library Browser?按钮?。
向模型中添加模块一个模型至少要接收一个输入信号,对该信号进行处理,然后输出结果。
在Library Browser 中,Sources 库包含代表输入信号的模块。
Sinks 库包含用于捕获和显示输出的模块。
其他库包含可用于各种用途(如数学运算)的模块。
在此基本模型中,输入信号为正弦波,执行的操作为增益运算(通过乘法增加信号值),结果输出到一个 Scope 窗口。
尝试使用不同的方法来浏览库,并向您的模型中添加模块。
1.打开 Sources 库。
在 Library Browser 的树视图中,点击?Sources?库。
2.在右窗格中,将光标悬停在?Sine Wave?模块上,以查看描述其用途的工具提示。
3.使用上下文菜单在模型中添加一个模块。
右键点击该模块并选择?Addblock to model untitled。
(要了解该模块的详细信息,请从上下文菜单中选择?Help。
)4.通过拖放操作在模型中添加一个模块。
在库树视图中,点击?MathOperations。
在 Math Operations 库中,找到?Gain?模块,然后将其拖到模型中?Sine Wave?模块的右侧。
5.在库树视图中,点击?Simulink,查看以图标形式显示在右窗格中的子库。
此视图是导航库结构的另一种方法。
双击?Sinks?库图标。
6.在 Sinks 库中,找到?Scope?模块,然后使用上下文菜单或通过拖放操作将其添加到模型中。
现在,您的模型如下图所示。
对齐和连接模块可将模块连接起来,在模型元素之间建立能够使模型正常工作所需要的关系。
当您根据模块之间的交互方式对齐模块后,模型将更加一目了然。
快捷方式可以帮助您对齐和连接模块。
1.拖动 Gain 模块,使其与 Sine Wave 模块对齐。
当两个模块水平对齐时,将出现一条对齐参考线。
释放模块,此时将出现一个蓝色箭头,作为建议连接线的预览。
2.要接受该连接线,请点击箭头的末端。
此时参考线将变成一条实线。
3.采用同样的方法,将 Scope 模块与 Gain 模块对齐并连接起来。
提示可以使用?Diagram?>?Arrange?菜单查看其他对齐方式选项。
设置模块参数您可以设置大多数模块上的参数。
参数可以帮助您指定模块如何在模型中工作。
您可以使用默认值,也可以根据需要设置值。
可以使用 Property Inspector 设置参数。
也可以双击大多数模块,使用模块对话框来设置参数。
要了解何时使用每一种方式,请参阅设置属性和参数。
在模型中,您可以在?Sine Wave?模块中设置幅值,在?Gain?模块中设置增益值。
1.显示 Property Inspector。
选择?View?>?Property Inspector。
2.选择?Sine Wave?模块。
3.在 Property Inspector 中,将?Amplitude?参数设置为?2。
4.选择?Gain?模块并将?Gain?参数设置为?3。
该值将显示在模块上。
添加更多模块假设您要再执行一个增益运算,但这次针对的是?Sine Wave?模块的输出绝对值。
为了实现此目的,需要添加一些模块,请尝试通过不同的方式找到库中的模块并添加到模型中。
1.如果知道要添加的模块的名称,可以使用快捷方式。
点击模型中要添加模块的位置,然后键入模块名称(在本例中为 Gain)。
此时将显示一个可能的模块列表。
2.点击模块名称,或者在突出显示模块名称后按?Enter。
如果它不是列表中的第一个模块,您可以使用箭头键突出显示模块名称。
使用此方法可以在出现蓝色放大镜的任何位置添加模块,例如在您绘制信号线时。
3.许多模块会显示要求您为某个模块参数输入值的提示。
Gain?模块会提示您输入?Gain?值。
键入?3?并按?Enter。
每增加一个模块实例,名称中的数字就会增加 1,例如 Gain1、Gain2 等。
4.在模型中添加一个?Abs?模块。
假定您不知道模块在哪个库中,也不知道模块的完整名称。
这种情况下,可以使用 Library Browser 中的搜索框进行搜索。
在搜索框中输入?abs?并按?Enter。
当您找到 Abs 模块后,将其添加到Gain1 模块的左侧。
5.添加另一个 Scope 模块。
您可以右键点击并拖动现有的 Scope 模块为其创建一个副本,或使用?Edit?>?Copy?和Edit?>?Paste。
下图显示了您的模型的当前状态。
注意当您按照数字顺序为模型中的模块命名时(例如 Gain1、Gain2 等),复制和粘贴操作将按照 ASCII 字符的标准排序约定生成模块名称。
这种排序方法可能会导致模块名称中出现一串难以理解的数字。
如果编号方案对您很重要,请为模块编号,使复制和粘贴操作生成的模块名称遵循常见的阅读顺序。
为此,请在模块名称中使用前导零,例如 Gain001、Gain002 等。
建立分支连接第二个增益运算的输入是正弦波的绝对值。
要使用一个?Sine Wave?模块作为两个增益运算的输入,需要从?Sine Wave?模块输出信号上创建一条分支。
1.对于模型中的第一组模块,您使用了水平对齐参考线帮助您对齐和连接模块。
您还可以使用参考线垂直对齐模块。
将 Scope1 模块拖动到 Scope 模块下面并与之对齐。
当垂直对齐参考线显示两个模块已对齐时,释放模块。
2.按下图所示对齐并连接 Abs 和 Gain1 模块。
3.从 Sine Wave 模块的输出端口创建一条连接到 Abs 模块的分支线。
当光标悬停在 Sine Wave 模块的输出信号线上时,按住?Ctrl?键并向下拖动。
拖动分支线,直到末端靠近 Abs 模块为止。
4.向 Abs 模块拖动,直到分支线连接到该模块。
根据需要移动顶点,以拉直该线。
(顶点上出现一个圆圈。
)您可以尝试用其他方法来连接模块:•拖动鼠标,从一个模块的输出向另一个模块的输入绘制一条连接。
当您的模块已对齐(即不显示参考线)时,可以使用此方法。
•选择第一个模块,然后按住?Ctrl?键并点击要连接的模块。
当您不希望模块对齐时,可以使用此方法。
连接线根据需要拐弯以建立连接,如下图所示。
注意您可以选择多个模块,将它们连接到一个具有多个输入端口的模块(例如,总线)。
要从线段逼近对角线,请按住?Shift?键并拖动顶点。
提示要改善信号线的形状,请选择信号线,然后从省略号菜单中选择?Autoroute Line。