You are on page 1of 2

Matlab exercises, 3rd session

Graphical user interface


1. Implement the example that is in the lecture slides, i.e. a GUI with two buttons (Push Button) and one text field (Static Text). When the first button is pressed, the text field should say You have pressed the button!. When the second button is pressed, the text field is cleared. 2. Implement a simple GUI that can be used to draw a sinusoid. The user gives the amplitude, the frequency and the final time. The GUI could look like this:

Hints: Edit Text components are used to give the amplitude, the frequency and the final time. The values given by the user are stored to the field String of the components mentioned above. The values must be retrieved from these fields and converted to numeric variables with the command str2num before drawing. The command axes is used to define the axes that are used for drawing, axes(handle). The command must be given before the sinusoid is drawn.

3. Make a simple graphical calculator. The calculator must have buttons (Push Button) for numbers and for mathematical operations (*,/,+,-) as well as execute and clear buttons. You can also add a backspace button is you want to do so. You also need a display (Static Text). One way to implement the calculator is to add the character that is pressed to the string on the display. When the execute button is pressed, the value of the string is

evaluated using Matlabs eval command. This kind of calculator does not give intermediate results, only the final one. 4. Save the file temperatures.zip from the course home page to the directory you use for todays exercises. Unzip the file. In the directory there should appear five text files aug.txt, sep.txt, oct.txt, nov.txt and dec.txt. Each file contains the temperatures in Otaniemi between August and December 2004. In the files there are two columns; the first column contains time stamps in Matlabs serial date number form and the second column contains the measured temperatures. Make a GUI that can be used to plot the temperatures of different months to a plot in the GUI. The GUI must contain a button that is used for loading the data into the GUI. You also need buttons for plotting the temperatures of each month. Additionally, create a button that can be used for plotting several months at the same time (hold) and a button for adding gridlines (grid). Add a title and labels. Here is an example of what the GUI could look like. Please, make your own and do not copy this one directly!

You might also like