Matlab Exercises 2: X (0:360) Y1 Sin (X Pi/180) Y2 Cos (X Pi/180) Y3 Tan (X Pi/180)
Matlab Exercises 2: X (0:360) Y1 Sin (X Pi/180) Y2 Cos (X Pi/180) Y3 Tan (X Pi/180)
MATLAB EXERCISES 2
x=[0:360];
y1 = sin(x*pi/180);
y2 = cos(x*pi/180);
y3 = tan(x*pi/180);
Note – the property editor changes as you select different axes/lines. If you select 'more properties' button a
separate window will open showing ALL the properties available. Experiment with different axis and line properties.
The Figure Palette / Annotations menu allows you to add arrows, lines, text etc. Try adding arrows with labels
pointing out different features on the plots.
While the interactive property editor is useful for quick one-off changes to a single figure, it would be tedious to
adjust a large number of figures like this. It is much better, and often faster, to use the command line to make
changes - this is also essential in order to write programs that create high quality figures. In the tasks below, use the
command line only, saving the handles to objects as you create them and then using these to change the properties
of the objects. You can see ALL the properties of a given object (both names and values) with the command
get(H) where H is the object's handle - if you don't know the property name you need to adjust, this is a good
place to start looking...the other place is the helpdesk's handle graphics property browser.
Create a new figure window and create a first set of axes with
ax1 = subplot(2,1,1)
Plot both the sine (y1) and cosine (y2) series against x on this axis, saving the handles to the lines as you do so.
Now try the following:
Change the line properties for the sine curve to colour red and width 2
Change the cosine curve to a green dashed line with a width of 3
Change the x-axis limits to 0 to 360
Change x-axis tick intervals to 30
Use the xlabel function to add an axis label to the x-axis
Use the legend function to add a legend showing which line is which.
Add a second axis below the first ( subplot(2,1,2) ) and plot the y3 against x in it.
set the x-axis limts and tick intervals to match those in the first axis, and the ylimits to +/- 60 with ticks at intervals of
20.
Add an x-label, and legend for the line.
increase the font size on the axis to 12 point.
set the linewidths of both axes to 2
If you don't save an object's handle when it is created you can always discover it later - if you click on an object it
becomes the current object, you can then use the functions gcf (get current figure), gca (get current axis) and
gco (get current object) to access the handle - note that clicking on a line makes the line the current object, the axis
it is in the current axis, and the figure it's in the current figure.
homepages.see.leeds.ac.uk/~lecimb/matlab/exercises-2.html 1/2
9/6/2020 Matlab Exercises 2
Try adding a few lines to a figure, then select each in turn and removing them with delete(gco)
3D Plots Exercise
Use the peaks function to generate a dataset consisting of x and y coordinates and z a function of x and y:
[x,y,z] = peaks;
Now create a new figure with a pcolor(x,y,z)plot, and make the additions and adjustments noted below -
save handles as you go...you may need them:
you should have a figure like this. Now make the following changes:
[how]
homepages.see.leeds.ac.uk/~lecimb/matlab/exercises-2.html 2/2