0% found this document useful (0 votes)
144 views10 pages

Simulink & GUI in MATLAB: Experiment # 5

This document describes using Simulink and GUI in MATLAB. It provides an example of modeling the Celsius to Fahrenheit temperature conversion equation in Simulink, including specifying the blocks, parameters, and obtaining the output graph. It also demonstrates how to build a simple calculator GUI in MATLAB, including adding buttons and text displays, assigning callbacks, and evaluating input.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
144 views10 pages

Simulink & GUI in MATLAB: Experiment # 5

This document describes using Simulink and GUI in MATLAB. It provides an example of modeling the Celsius to Fahrenheit temperature conversion equation in Simulink, including specifying the blocks, parameters, and obtaining the output graph. It also demonstrates how to build a simple calculator GUI in MATLAB, including adding buttons and text displays, assigning callbacks, and evaluating input.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Experiment # 5

Simulink & GUI in MATLAB

Introduction to simulink

SIMULINK is an interactive environment for modeling, analyzing, and simulating a


wide variety of dynamic systems. SIMULINK provides a graphical user interface for
constructing block diagram models using “drag-and-drop” operations. A system is
configured in terms of block diagram representation from a library of standard
components. SIMULINK is very easy to learn. A system in block diagram
representation is built easily and the simulation results are displayed quickly.
Simulation algorithms and parameters can be changed in the middle of a simulation
with intuitive results, thus providing the user with a ready access learning tool for
simulating many of the operational problems found in the real world. SIMULINK is
particularly useful for studying the effects of nonlinearities on the behavior of the
system, and as such, it is also an ideal research tool. The key features of SIMULINK
are
 Interactive simulations with live display.
 A comprehensive block library for creating linear, nonlinear, discrete or hybrid
multi-input/output systems.
 Seven integration methods for fixed-step, variable-step, and stiff systems.
 Unlimited hierarchical model structure.
 Scalar and vector connections.
 Mask facility for creating custom blocks and block libraries. SIMULINK provides
an open architecture that allows you to extend the simulation environment:
 You can easily perform “what if” analyses by changing model parameters – either
interactively or in batch mode – while your simulations are running.
 Creating custom blocks and block libraries with your own icons and user
interfaces from MATLAB, Fortran, or C code.
 You can generate C code from SIMULINK models for embedded applications and
for rapid prototyping of control systems.
 You can create hierarchical models by grouping blocks into subsystems. There are
no limits on the number of blocks or connections.
 SIMULINK provides immediate access to the mathematical, graphical, and
programming capabilities of MATLAB, you can analyze data, automate
procedures, and optimize parameters directly from SIMULINK.
 The advanced design and analysis capabilities of the toolboxes can be executed
from within a simulation using the mask facility in SIMULINK.
 The SIMULINK block library can be extended with special-purpose blocksets. The
DSP Blockset can be used for DSP algorithm development, while the Fixed-Point
Blockset extends SIMULINK for modeling and simulating digital control systems
and digital filters.

5.1) Simulation Parameters and Solver


You set the simulation parameters and select the solver by choosing Parameters from
the Simulation menu. SIMULINK displays the Simulation Parameters dialog box,
which uses three “pages” to manage simulation parameters. Solver, Workspace I/O,
and Diagnostics.

SOLVER PAGE

The Solver page appears when you first choose Parameters from the Simulation
menu or when you select the Solver tab. The Solver page allows you to:
 Set the start and stop times – You can change the start time and stop time for
the simulation by entering new values in the Start time and Stop time fields.
The default start time is 0.0 seconds and the default stop time is 10.0 seconds.
 Choose the solver and specify solver parameters – The default solver provide
accurate and efficient results for most problems. Some solvers may be more
efficient that others at solving a particular problem; you can choose between
variable-step and fixed-step solvers. Variable-step solvers can modify their
step sizes during the simulation. These are ode45, ode23, ode113, ode15s,
ode23s, and discrete. The default is ode45. For variable-step solvers, you can
set the maximum and suggested initial step size parameters. By default, these
parameters are automatically determined, indicated by the value auto. For
fixed-step solvers, you can choose ode5, ode4, ode3, ode2, ode1, and
discrete.
 Output Options – The Output options area of the dialog box enables you to
control how much output the simulation generates. You can choose from three
popup options. These are: Refine output, Produce additional output, and
Produce specified output only.

WORKSPACE I/O PAGE


The Workspace I/O page manages the input from and the output to the MATLAB
workspace, and allows:
 Loading input from the workspace – Input can be specified either as MATLAB
command or as a matrix for the Import blocks.
 Saving the output to the workspace –You can specify return variables by
selecting the Time, State, and/or Output check boxes in the Save to workspace
area.

DIAGNOSTICS PAGE
The Diagnostics page allows you to select the level of warning messages displayed
during a simulation.

NOW, make this example:

Model the equation that converts Celsius temperature to Fahrenheit. Obtain a display
of Fahrenheit-Celsius temperature graph over a range of 0 to 100  C .
9
TF  TC  32
5
First, consider the blocks needed to build the model. These are:
 A ramp block to input the temperature signal, from the source library.
 A constant block, to define the constant of 32, also from the source library.
 A gain block, to multiply the input signal by 9=5, from the Linear library.
 A sum block, to add the two quantities, also from the Linear library.
 A scope block to display the output, from the sink library.
To create a SIMULINK block diagram presentation select new... from the File menu.
This provides an untitled blank window for designing and simulating a dynamic
system. Copy the above blocks from the block libraries into the new window by
depressing the mouse button and dragging. Assign the parameter values to the Gain
and Constant blocks by opening (double clicking on) each block and entering the
appropriate value. Then click on the close button to apply the value and close the
dialog box. The next step is to connect these icons together by drawing lines
connecting the icons using the left mouse button (hold the button down and drag the
mouse to draw a line).
You should now have the SIMULINK block diagram as shown below:

The Ramp block inputs Celsius temperature. Open this block, set the Slope to 1, Start
time to 0, and the Initial output to 0. The Gain block multiplies that temperature by
the constant 9/5. The sum block adds the value 32 to the result and outputs the
Fahrenheit temperature. Pull down the Simulation dialog box and select Parameters.
Set the Start time to zero and the Stop Time to 100. Double click on the Scope, click
on the Auto Scale, the result is displayed as shown below
Building GUI interfaces in Matlab

This example shows how to build user GUI in Matlab. We will build a simple
calculator to do that.
Start gui builder by typing
>>guide

Select "Blank GUI", click OK

The GUI window will open


Resize the design window.
Using the pallette on the left, drag and drop, resize and position the canvas, buttons,
and static text windows.

Double-click on an object to open the properties dialog. Change the captions on the
buttons and remove "Static Text" string from the text window. Set the font size 30 for
the text windows and change horizontal alingment to "right."
The GUI is finished. Save the work.
The rest of the design process will take care of the functionality provided by each
GUI component.

Open the matlab editor by typing


>>edit foo.m
where foo.m is the name of your design

Each time you press a button, a callback function is executed.


For example, in this particular case, a click on button "1" will call the following
function:
This function will have to be modified to provide required functionality.
Buttons "0"-"9","+","-","*","/" will add corresponding symbol to the text string
displayed on the top. For button "1" the code will look like:

Do the same for the rest of the buttons, except "=".


The "=" button should evaluate the text string in the text window and return the result.
Now the calculator is ready to use. Of course, it misses a lot of functionality, but

LAB
1. Implement the below function by Simulink

X 2 3

Be sure that the range of the function appears in scope between (-3,10).

2. Implement the below transfer function using Simulink

2S  3
2
S  3S  2

3. Implement the Calculator GUI .

You might also like