Build Model & Apply If-else Logic ”; Previous Next In this chapter, we will create a model and apply if-else logic to it. Let us first collect blocks to create our model. Now, open MATLAB Simulink (blank model) and the Simulink library browser as shown below − Click on the Blank Model and open Simulink library browser as shown below − The blocks we require to build the model with if-else logic is as follows − Constant block from Commonly used blocks Switch block from Signal Routing Display block from Sinks Let us now get all the blocks together to create a model as shown below − Let us now connect the lines with each block. So you can see that the constant block has one output and the switch has three inputs and one output. We are going to connect them to the display block. After connecting the lines, the model is as shown below − Now, double click the switch block and add a threshold. The threshold value will be compared with the block in the center. Based on the constant value of the middle block, the first block value will be displayed or the last constant block value will be displayed. Let us add a threshold value to the switch as shown below − The threshold value given is 3. Click on OK to update the threshold. Now the threshold value is seen inside the switch block as shown below − The middle constant block will be compared with the switch threshold and accordingly the display will be decided. Let us now update the middle constant block with some value as shown below − The value of the constant block is 1. Let us now change the first constant block and give it a value as 0.5 as shown below − Let us now change the last constant with value as 2.5 as shown below − Hence, the first constant value is 0.5, the middle constant value is 1 and the last one is 2.5. The middle constant value 1 will be compared to switch threshold value i.e. 3 as (1 >3). It will print the value as 2.5 the last constant value. Click on the run button to get the output in the display block as shown below − Let us now change the middle constant to a higher value than the threshold of switch and see the output − The value is changed from 1 to 3.5. Click on OK and run the model to see the output in the display − Now, since the value of the middle constant is greater, the value from the first constant is printed in display. If it is less, then the value from the last constant will be printed. Print Page Previous Next Advertisements ”;
Category: matlab Simulink
MATLAB Simulink – Starting Simulink ”; Previous Next In this chapter, we will understand about using Simulink to build models. Here is a MATLAB display − You can start Simulink by using simulink command in the MATLAB command window as shown below − Click on enter to open the Simulink startup page as shown below − You can also open Simulink from MATLAB interface directly by clicking on Simulink icon as shown below − When you click on the Simulink icon, it will take you to a Simulink startup page, as shown below − The startup page has a blank model, subsystem, library to start the model from scratch. There are also some built-in templates that can help the users to start with. To create a model, the user can click on blank model and it will display a page as shown below − Click on Save to save your model. The blocks to build your model are available inside the Simulink library browser. Click on library browser as shown below − The library browser has a list of all types of libraries with different blocks as shown below − Libraries in Simulink Let us understand some of the commonly used libraries in Simulink. Continuous A continuous blocks library gives you blocks related to derivatives and integrations. The list of blocks are as follows − Dashboard With Dashboard, you will get controls and indicator blocks that help to interact with simulations. The following screen will appear on your computer − Discontinuities Here, you will get a list of discontinuous functions blocks as displayed below − Discrete Here, you will get time relation function blocks as shown below − Logic and Bit Operations In this category, you will get all logical and relational type blocks as displayed below − Lookup Tables You will all the sine, cosine function blocks as shown below − Math Operations All mathematical operations like Add, Absolute, divide, subtract are available. The list is as follows − Messages and Events This block has all the message/communication related functions as shown below − Model Verification The blocks present here helps to self-verify models, such as Check Input Resolution. The following screen will appear on your computer − Model-Wide Utilities This gives you blocks like Model info, Block Support Table etc. The following screen will appear on your computer − Ports and Subsystems You will get blocks like a subsystem, switch case, enable etc. The list is displayed below − Signal Attributes Modify the signal attribute blocks such as Data Type Conversion. The following screen will appear on your computer − Signal Routing The blocks in this category is used to route signal blocks such as bus creator, switch etc.The following screen will appear on your computer − Sinks The blocks in this category help to display or export signal data blocks such as Scope andTo Workspace. The following screen will appear on your computer − Sources It helps to generate or import data blocks. For example, sine wave. The following screen will appear on your computer − String This category has string related blocks as shown below − User Defined functions Custom function blocks such as MATLAB Function, MATLAB System, Simulink Function, and Initialize Function. The following screen will appear on your computer − Print Page Previous Next Advertisements ”;