You are on page 1of 3

Lab5 Excercise

Fall 2016

Name:

Student #:

For this exercise, you will develop a GUI to simulate a pressure monitoring system. Here, you will need to
apply knowledge gained from the lab activity conducted previously to develop the necessary code. A brief
description of programming knowledge required for this activity is provided below.
A variable is a container in which data can be stored. Data such as integers or strings can be stored in a
variable. A variable may also point to an array of numbers or strings. In Lab 5, data is a variable which holds
the data output from the DAQ.
A function is a essentially a sequence of instructions which accepts an argument (which can also be a function),
and returns a result. In Lab 5, functions such as set() and mean() were used to set a GUI property and obtain the
mean value of a dataset respectively. A function call typically follows the form:
variable = function(argument_1,argument_2,,argument_n)

The first term variable holds the result of the function. The function term is the function being called. The
arguments are the terms being fed into the function. The function set() has the following format:
set(object,property,value)

Where object is the name or handle of the GUI object being affected, the property is what is being affected
within this object, and value is the data being set. In Lab 5 we used the set() function in the following manner:
set(handles.mybox,'String', num2str(N))

Here, handles.mybox refers to the static text box created to display the mean, 'String' is the property being
changed (think of the selections within the Propety Inspector) and num2str(N) is the value being set.
Recall from Lab 5, handles allow data to be passed between functions. In order to make the handle available,
the following line of code needs to be added to the end of the callback function:
guidata(hObject,handles)

To generate simulated data values, the randi() or rand() functions will need to be used. These functions generate
random values and follow this format:
randi(maxValue, m, n)

Here, randi will generate random integers between 1 and maxValue and input them into a matrix with m rows
and n columns. The rand() function works similarly, however there is no option to constrain the bounds. Be
aware that these functions still require variables to hold their result.
rand(m, n)

Finally, recall in Lab 2 exercise the use of an if statement to create a decision-making framework within
LabView. The same will be required here using the following format:
if(argument)
result if argument is true
else
result if argument is false
end

Additional information on the functions and terms used above can be found in the Matlab documentation.
1. Create a GUI that has the controls as shown in Fig.1. Change the properties (e.g. text, background
color,..) accordingly to look exactly like the picture.
Hint : (boxes showing 30 and 12 on the GUI are just Textboxes with initial values of 30 and 12)

Figure 1: GUI to be developed

Write the proper Matlab code in the Call back functions of necessary controls so that followings functions are
available for each control on the GUI:
Read Pressure Data: This control button uses Randi and Randn commands to create 10 random data
ranging between 0V to 10V to be used by GUI. (Hint: use Matlab Help on these two commands and look into
the examples provided by Matlab in the help)
Clicking on this button also verifies the range of data and makes the green Normal Limit textbox visible if
data is between 1V and 8V. Otherwise it makes the red Over limit textbox visible. Please note only one
textbox can be visible at a time. (as shown in Figure 2 and Figure 3).
Plot Pressure Data: Plots the latest 10 data generated by Read Pressure Data control on the Plot window. It
holds the last graph on the window every time a new graph is plotted.
Maximum Pressure: Clicking on this button, finds the maximum of the latest 10 generated data and shows it
on a textbox in front of it.

Minimum Pressure: Clicking on this button, finds the minimum of the latest 10 generated data and shows it on
a textbox in front of it.

Figure 2 and 3 are showing the example of running the GUI with normal limit and over limit data generated by
the GUI.
2. Run the GUI. Click on different control buttons and test the functionality of your GUI to generate, plot
and analyze the maximum, minimum and range of data. Show the result to your lab instructor.

Figure 2: Example of normal limit data plotted on GUI

Figure 3: Example of over limit data plotted on GUI

You might also like