MATLAB fundamentals 11
2.1 The MATLAB desktop
The default MATLAB desktop is shown in Figure 1.1. It should immediately be stressed that MATLAB
has an extremely useful online Help system. If you are serious about learning MATLAB you should make
it your business to work through the various Help features, starting with the section on the desktop.
To get into the Help browser, either expand the MATLAB item in the Launch Pad and click on Help,
or click on the help button (?) in the desktop toolbar, or select the Help menu in any tool. Having
opened the Help browser, select the Contents tab in the Help Navigator pane on the left. To get to the
desktop section expand successively the MATLAB, Getting Started and Development Environment
items. MATLAB Desktop is listed under the latter. When you’ve looked at the Desktop item you should
go on to Desktop Tools. (If you mess up your desktop and want to get back to the default, select the
View -> Desktop Layout -> Default menu item.)
The desktop contains a number of tools. We have already used the Command Window. On the left is
the Launch Pad, which shares a ‘docking’ position with the Workspace browser (underneath the Launch
Pad in the default). Use the tabs to switch between the Launch Pad and the Workspace browser. Below
the Launch Pad you will find the Command History, sharing with the Current Directory browser.
You can resize any of these windows in the usual way. A window can be moved out of the MATLAB
desktop by undocking it. Do this either by clicking on the arrow in the window’s title bar, or by making
the window active (click anywhere inside it) and then selecting Undock from the View menu.
To dock a tool window that is outside the MATLAB desktop (i.e. to move it back into the desktop)
select Dock from its View menu.
You can group desktop windows so that they occupy the same space in the MATLAB desktop. Access
to the individual windows is then by means of their tabs. To group windows in this way drag the title bar
of one window on top of the title bar of the other window. The outline of the window you’re dragging
overlays the target window, and the bottom of the outline includes a tab. The Status bar informs you to
Release the mouse button to tab-dock these windows. If you release the mouse the
windows are duly tab-docked in the outlined position.
There are six predefined MATLAB desktop configurations, which you can select from the View ->
Desktop Layout menu.
2.2 Programs
In Chapter 1 we saw some simple examples of how to use MATLAB, by entering single commands
or statements at the MATLAB prompt. However, you might want to solve problems which MATLAB
can’t do in one line, like finding the roots of a quadratic equation (and taking all the special cases into
account). A collection of statements to solve such a problem is called a program. In this section we look
at the mechanics of writing and running two short programs, without bothering too much about how they
work—explanations will follow in the rest of the chapter.
Cut and paste
Suppose you want to draw the graph of e
−0.2x
sin(x) over the domain 0 to 6π , as shown in Figure 2.1.
The Windows environment lends itself to nifty cut and paste editing, which you would do well to master.
Proceed as follows.
From the MATLAB desktop select File -> New -> M-file, or click the new file button on the desktop
toolbar. This action opens an Untitled window in the Editor/Debugger. You can regard this for the time
being as a ‘scratch pad’ in which to write programs. Now type the following two lines in the Editor,
exactly as they appear here:
x = 0 : pi/20 :6*pi;
plot(x, exp(-0.2*x) .* sin(x), ’r’),grid
Incidentally, that is a dot (full stop, period) in front of the second * in the second line—explanation
later! The additional argument ’r’ for plot will draw a red graph, just to be different.