in black and white
Main menu
Home About us Share a book
Biology Business Chemistry Computers Culture Economics Fiction Games Guide History Management Mathematical Medicine Mental Fitnes Physics Psychology Scince Sport Technics

A Guide to MATLAB for Beginners and Experienced Users - Brian R.H.

Brian R.H., Roland L.L. A Guide to MATLAB for Beginners and Experienced Users - Cambrige, 2001. - 346 p.
Download (direct link): beginnersandex2001.pdf
Previous << 1 .. 7 8 9 10 11 12 < 13 > 14 15 16 17 18 19 .. 91 >> Next

>> ezplot('exp(-x)', [0 10]) >> hold on

>> ezplot('sin(x)', [0 10]) >> hold off

>> title 'exp(-x) and sin(x)'

The result is shown in Figure 2-3 earlier in this chapter. The commands hold on and hold off work with all graphics commands.

With plot, you can plot multiple curves directly. For example,

>> X = 0:0.1:10;

>> plot(X, exp(-X), X, sin(X))

Note that the vector of x coordinates must be specified once for each function being plotted. Chapter 3

Interacting with MATLAB

In this chapter we describe an effective procedure for working with MATLAB, and for preparing and presenting the results of a MATLAB session. In particular we will discuss some features of the MATLAB interface and the use of script M-files, function M-files, and diary files. We also give some simple hints for debugging your M-files.

The MATLAB Interface

MATLAB 6 has a new interface called the MATLAB Desktop. Embedded inside it is the Command Window that we described in Chapter 2. If you are using MATLAB 5, then you will only see the Command Window. In that case you should skip the next subsection and proceed directly to the Menu and Tool Bars subsection below.

The Desktop

By default, the MATLAB Desktop (Figure 1-1 in Chapter 1) contains five windows inside it, the Command Window on the right, the Launch Pad and the Workspace browser in the upper left, and the Command History window and Current Directory browser in the lower left. Note that there are tabs for alternating between the Launch Pad and the Workspace browser, or between the Command History window and Current Directory browser. Which of the five windows are currently visible can be adjusted with the View: Desktop Layout menu at the top of the Desktop. (For example, with the Simple option, you see only the Command History and Command Window, side-by-side.) The sizes of the windows can be adjusted by dragging their edges with the mouse.

31 32

Chapter 3: Interacting with MATLAB

The Command Window is where you type the commands and instructions that cause MATLAB to evaluate, compute, draw, and perform all the other wonderful magic that we describe in this book. The Command History window contains a running history of the commands that you type into the Command Window. It is useful in two ways. First, it lets you see at a quick glance a record of the commands that you have entered previously. Second, it can save you some typing time. If you click on an entry in the Command History with the right mouse button, it becomes highlighted and a menu of options appears. You can, for example, select Copy, then click with the right mouse button in the Command Window and select Paste, whereupon the command you selected will appear at the command prompt and be ready for execution or editing. There are many other options that you can learn by experimenting; for instance, if you double-click on an entry in the Command History then it will be executed immediately in the Command Window.

The Launch Pad window is basically a series of shortcuts that enable you to access various features of the MATLAB software with a double-click. You can use it to start SIMULINK, run demos of various toolboxes, use MATLAB web tools, open the Help Browser, and more. We recommend that you experiment with the entries in the Launch Pad to gain familiarity with its features.

The Workspace browser and Current Directory browser will be described in separate subsections below.

Each of the five windows in the Desktop contains two small buttons in the upper right corner. The x allows you to close the window, while the curved arrow will "undock" the window from the Desktop (you can return it to the Desktop by selecting Dock from the View menu of the undocked window). You can also customize which windows appear inside the Desktop using its View menu.

? While the Desktop provides some new features and a common interface for both the Windows and UNIX versions of MATLAB 6, it may also run more slowly than the MATLAB 5 Command Window interface, especially on older computers. You can run MATLAB 6 with the old interface by starting the program with the command matlab /nodesktop on a Windows system or matlab -nodesktop on a UNIX system. If you are a Windows user, you probably start MATLAB by double-clicking on an icon. If so, you can create an icon to start MATLAB without the Desktop feature as follows. First, click the right mouse button on the MATLAB icon and select Create Shortcut. A new, nearly identical icon will appear on your screen (possibly behind a window you may need to hunt for it). Next, click the right mouse button on the new icon, and select Properties. In the panel that pops up, select the The MATLAB Interface 33

Shortcut tab, and in the "Target" box, add to the end of the executable file name a space followed by /nodesktop. (Notice that you can also change the default working directory in the "Start in" box.) Click OK, and your new icon is all set; you may want to rename it by clicking on it again with the right mouse button, selecting Rename, and typing the new name.
Previous << 1 .. 7 8 9 10 11 12 < 13 > 14 15 16 17 18 19 .. 91 >> Next