You are on page 1of 2

Matlab exercises, 2nd session

Plotting
1. On the home page of the course there is a file that contains lengths and volumes of trees as well as the instants the trees were felled (the first column is the felling time, second the length and third the volume). Save this file (timeData.mat) to a directory Matlab can access. Create a script that first loads the variable data in timeData.mat into Matlabs workspace. Then save felling times, lengths and volumes as own variables. Change felling times as Matlabs serial date numbers. Sort data in ascending order using felling times as a criterion. Finally plot the data. The objective is to create a figure like the one below. Use functions datenum and datetick to create the x-axis tick labels. Hint: functions cell2mat, sortrows
Tree lengths 3

2.5

2 09/02/02

10/12/02

11/20/02

12/30/02

02/07/03

03/19/03

Tree volumes 0.045 0.04 m3 0.035 0.03 09/02/02

10/12/02

11/20/02
100 90 80 70 60 Italy 50 40 30 20 10 0 10

12/30/02

02/07/03

03/19/03

2. On the home page of the course there is a file called comparison.mat. The file contains information about eating habits in different countries. Study graphically if there are big differences in Finnish and Swedish eating habits. Each row in the matrix X contains information about one country. The names of the countries are in variable country and explanations for the columns in variable food. You are supposed to use function gname to solve the exercise. If you have time and are interested, you can study the data further. The result should be a figure like the one on the right containing data from Germany and Italy.

Garlic

20

30

40

50 60 Germany

70

80

90

100

3. Familiarize yourself with function ginput. You are supposed to make a drawing program of your own. In the program the user gives points with the mouse. Every time the user gives a point, the new point is connected to the previous one with a straight line. The last point is given using the rightmost button of the mouse. Before letting the user to input points, change the axes of the figure to be between 0 10. Example figure:
10

10

4. Plot a 3D figure and a contour plot of the function z = ( x 2 + 2 y 2 ) e1 x

y2

, when

2 x, y 2 . Use 20 contour lines in the contour plot. Give titles to the figures and add labels to the axes. Try different functions for drawing the 3D plot (plot3, mesh, surf, others?).

5. Plot the spiral x = t sin ( 6t ) , y = t cos ( 6t ) , z = t / 3 and the cone z =

x , y , 0 t . The figure should look like this:


Cone and spiral

1 2 x + y 2 , when 3

1.5

1 z axis 0.5 0 4 2 0 -2 y axis -4 -4 0 -2 x axis 2 4

You might also like