| Introduction | Exercise 1 |
| Starting up Matlab | Exercise 2 |
| Using a browser to download files | Exercise 3 |
| Getting help | |
| Quitting | |
| Lab summaries | |
| More on Matlab |
This lab will occupy today's lab session only. This session will introduce the mechanics of using Matlab on the Linux computers here in the lab. There is some reading to be completed before the second session and you can do that here in the lab or at any other computer with web access. The second lab, two sessions long, will present exercises in Matlab use.
The discussion that follows assumes that you are basically familiar with using a Unix-like operating systems such as Linux, browsing the Web, and, to a lesser extent, using telnet (or ssh) to log in to campus computers. The next few paragraphs will give a brief introduction to Matlab and explain how to use it and those aspects of the environment that will be important to doing the labs.
In this section you will see how to start up recent versions of Matlab that use the Java windowing interface. These instructions are the same for the Unix and MS-Windows versions of Matlab. I will also give the command-line equivalents of many of the commands. These command-line equivalents are valid for all versions of Matlab, and many of them are valid for the Matlab clone named Octave. Generally speaking, anything you can do using a menu can also be done with command-line equivalents. You would use the equivalents when writing scripts and the menus when working interactively.
The default window is divided into a larger pane on the right, and two
panes, each with identification tabs at the bottoms, on the left. The
right windowpane is a command windowpane and you will be typing Matlab
commands in it. On the left side of this command windowpane somewhere
(near the bottom in the figure) there will be a prompt of the form
». Your typed commands go next to this prompt.
There are two choices for display on each of the two windowpanes on the left. I suggest that you choose ``Workspace'' on the top and ``Command History'' on the bottom in general, although we will have occasion to use ``Current Directory'' on the bottom.
If you wish to use the command line to create and switch directories, you create a directory named math2070 with the command
mkdir math2070and you can make it the current directory with the command
cd math2070You can always find the name of your current directory with the command
pwdand you can get a listing of the files in the current directory with either the command
diror the command
ls
Before going on, create the directory math2070, with subdirectories lab01, lab02, ..., lab09.
diary diary.txtThe name diary.txt is actually the name of the file that is created and you can use any name you like. It is a text file, and you should use .txt to name it. Before going on, type this command in the ``Command'' windowpane. Terminate the command by hitting the ``Enter'' key.
You should also, type a comment line that will help you identify your work later. It should start with the comment character, a percent sign %, and include the lab number and date. This line will serve as an identifier when you look at the file.
Some of the labs require that you download files from the web in order to use them. The following exercise illustrates how to download files. The file you will download is a very simple script file.
Right-mouse click on the file demoscript.m
to bring up a menu. Choose ``Save link as'' and a file save
box will pop up. Navigate to the directory you made: math2070/lab01,
and save the file with the name demoscript.m. You must use
the .m extension to tell Matlab that the file contains Matlab
commands. Return to the Matlab command window. The file should be
visible to Matlab, a fact that you can confirm with the dir
command or by its presence in the ``Current Directory'' windowpane.
Edit the file by typing the command
edit demoscript.mor by double-clicking on the file in the ``Current Directory'' windowpane, or using the ``File
You can tell Matlab to execute the file by typing its name, without the ``.m'', on the command line, or by choosing ``Run'' from the Debug menu on the edit window. (The final statements in the file and comments refer to the following exercise.)
The following two exercises illustrate the use of the debugging capability of Matlab. Most of the time you will be able to see what is wrong from the Matlab error messages, but sometimes the error is not obvious. In Exercise 2 below, you will see what you might do when you just cannot see why something is wrong.
dbstop if error dbstop if naninfor through the Debug menu on the Edit window.
dbquitThis action will return Matlab to its usual » prompt.
dbclear allor from the debugging menu in the edit window.
The following exercise illustrates how you can use the debugger to trace execution. It uses the same demoscript.m file as before.
It is important to be able to get help when you need it. Matlab provides two help facilities from inside Matlab itself and a third on the web. From the Matlab prompt you can type
help diaryor, in fact, help for any command. You will get a short description of how to use the command. When you write your own Matlab macro files, you should always include some special comments in the beginning of the file. The comments up to the first executable statement or blank line will be printed out in response to the help command. For example, the command
help demoscriptwill give a quick help message from the first three lines of demoscript.m. You may notice that the first of these lines is included in the file listing in the ``Current Directory'' windowpane.
A second way to get help from the command prompt is the following.
helpdeskThis command brings up a comprehensive help facility, the same one that the Help menu brings up. This help facility is very similar to the one on the web from the URL:
You exit Matlab by typing quit at the command line or by
using the File
Exit menu choice.
You should complete a report of the results you obtained for each completed lab. This report need not be elaborate. The report consists of at least two files: the original diary.txt file(s) plus a summary file. This summary file can be easily created as you do the lab by keeping a text file up in the editor and copying parts of the web page, your commands and output to the file as you work. Another way is to start from the diary.txt file and delete all your false starts and errors to produce a compact record. Click here to see a sample summary file.
This summary file is very important. It is what I will read first and, if it is well-written and the work is done correctly, I will not need to read anything else. Never put incorrect Matlab statements into your summary because it will take me a lot of time to discover you really didn't mean them. I expect to see
Do not write a summary of today's work. Instead, Instead, please read the following information about Matlab commands from either the PC here in the lab or from another computer on the web.
The Mathworks, maker of Matlab, includes a short tutorial on using Matlab called Getting Started This tutorial is also available from the Matlab command prompt with the command helpdesk and also from the Help menu, and, if you have your own copy of the Matlab manuals, it comprises the ``Getting Started'' book.
The beginning of the ``Getting Started'' tutorial is the best presentation of the general capabilities of Matlab that I have come across. In order to have an overview of Matlab, browse through the first sections of the tutorial. There are only the equivalent of about 35 pages of material here, mostly very easy to understand. The two most important chapters are Desktop Tools that covers use of the Matlab windows, and Manipulating Matrices that covers use of Matlab as a tool for mathematics.
Begin this tutorial now, during this lab session. Read as much of it as you can now, and complete it at home or from any convenient computer connected to the web. The list of topics that follows (roughly in order of appearance) are topics that will be necessary for this semester's labs. The next lab, addresses some of these topics, but you will be well-served if you have seen the introduction.
Back to MATH2070 page.