MATLAB EXERCISES 2


Create the arrays:

x=[0:360];
y1 = sin(x*pi/180);
y2 = cos(x*pi/180);
y3 = tan(x*pi/180);

Plot each in a separate subplot in a 2-by-2 grid on the same figure.

Use the property editor to:

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:

You should end up with a figure like this. [how]

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.

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;

Each of x,y, and z is a square matrix.

Try the following plot types:

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:

You should end up with a figure like this.

[how]


Home | IMB's Homepage