Download (direct link):
Configuring Your Web Browser
In this section, we explain how to configure the most popular Web browsers to display M-files in the M-file editor or to launch M-books automatically.
Microsoft Internet Explorer
IfMATLAB and Word are installed on your Windows computer then Internet Explorer® should automatically know how to open M-books. With M-files, it may give you a choice of downloading the file or "opening" it; if you choose the latter, it will appear in the M-file editor, a slightly stripped-down version of the Editor/Debugger.
The situation with Netscape Navigator® is slightly more complicated. If you click on an M-file (with the .m extension), it will probably appear as a plain text file. You can save the file and then open it if you wish with the M-file editor. On a PC (but not in UNIX) you can open the M-file editor without launching MATLAB; look for it in the MATLAB group under Start: Programs, or else look for the executable file meditor.exe (in MATLAB 5.3 and earlier, Medit.exe). If you click on an M-book (with the .doc extension), your browser will probably offer you a choice of opening it or saving it, unless you have preconfigured Netscape to open it without prompting. (This depends also on your security settings.) What program Netscape uses to openConfiguring Your Web Browser
Figure 10-1: The Netscape Preferences Panel.
a file is controlled by your Preferences. To make changes, select Edit: Preferences in the Netscape menu bar, find the Navigator section, and look for the "Applications" subsection. You will see a panel that looks something like Figure 10-1. (Its exact appearance depends on what version of Netscape you are using and your operating system.) Look for the "Microsoft Word Document" file type (with file extension .doc) and, if necessary, change the program used to open such files. Typical choices would be Word or Wordpad® in Windows and StarOffice® or PC File Viewer® in UNIX. Choices other than Word will only allow you to view, not to execute, M-books.Chapter 11
In this chapter, we offer advice for dealing with some common problems that you may encounter. We also list and describe the most common mistakes that MATLAB users make. Finally, we offer some simple but useful techniques for debugging your M-files.
Problems manifest themselves in various ways: Totally unexpected or plainly wrong output appears; MATLAB produces an error message (or at least a warning); MATLAB refuses to process an input line; something that worked earlier stops working; or, worst of all, the computer freezes. Fortunately, these problems are often caused by several easily identifiable and correctable mistakes. What follows is a description of some common problems, together with a presentation of likely causes, suggested solutions, and illustrative examples. We also refer to places in the book where related issues are discussed. Here is a list of the problems:
• wrong or unexpected output,
• syntax error,
• spelling error,
• error messages when plotting,
• a previously saved M-file evaluates differently, and
• computer won't respond.
Wrong or Unexpected Output
There are many possible causes for this problem, but they are likely to be among the following:
218Common Problems 219
cause: Forgetting to clear or reset variables.
solution: Clear or initialize variables before using them, especially in a long session.
^ See Variables and Assignments in Chapter 2. cause: Conflicting definitions.
solution: Do not use the same name for two different functions or variables, and in particular, try not to overwrite the names of any of MATLAB's built-in functions.
You can accidentally mask one of MATLAB's built-in M-files either with your own M-file of the same name or with a variable (including, perhaps, an inline function). When unexpected output occurs and you think this might be the cause, it helps to use which to find out what M-file is actually being referenced. Here is perhaps an extreme example.
>> plot = gcf; >> x = -2:0.1:2; >> plot(x, x."2)
Warning: Subscript indices must be integer values. ??? Index into matrix is negative or zero. See release notes on changes to logical indices.
What's wrong, of course, is that plot has been masked by a variable with the same name. You could detect this with
>> which plot
plot is a variable.
If you type clear plot and execute the plot command again, the problem will go away and you'll get a picture of the desired parabola. A more subtle example could occur if you did this on purpose, not thinking you would use plot, and then called some other graphics script M-file that uses it indirectly.
cause: Not keeping track of ans.
solution: Assign variable names to any output that you intend to use.
If you decide at some point in a session that you wish to refer to prior output that was unnamed, then give the output a name, and execute the command220