![]()
|
October 2007, for ACM 11 at Caltech
There is MUCH more at the following 2008 ACM 11 homepage, from when I was the instructor for the course. These notes are from 2007 when I was a TA.
Buying Matlab is an expensive proposition normally: without the add-ons, it is $500, and $1000 if you include SimuLink and the Symbolic Toolbox. Students can get Matlab and Simulink for $100. Each add-on is about $200 (though up to $500). Luckily for Caltech students, the Institute has a site license, which includes most of the useful add-ons. You can download a copy at software.caltech.edu (if you're off campus, use webVPN or a normal VPN). Once you install, you must be connected to the internet since matlab will look for Caltech's license server.
UPDATE: class members have reported not being able to use Matlab off campus, unless using a VPN. You should be able to use it off campus without a VPN -- and it definitely works for some people. So I'm not sure what's going on here. There are also issues installing Matlab on OS X and Vista; if you can't get it to work, try using the ITS cluster version (see next paragraph). For linux problems, email one of the TA's directly. With Vista, be careful about saving files to the default workspace directories, because you may not have permission to write here, and Windows will make a "compatability file" version.
Alternatively, you can use the Matlab version that is installed on the ITS unix cluster. Connect to this cluster (use a SSH program, eg. openSSH or PuTTY or X-Win32 [this isn't free, but Caltech has a license] ). By default, you're in the tcsh shell unless you've explicitly changed this. Matlab is installed at /ccovol/matlab/12/bin/matlab, and this should be in your path, so you can run the program with just matlab.
UPDATE: if you use a program with XWindows, you do NOT have to run matlab in the console. It will open a window, just as if it were on your own machine (it may run a bit slow, depending on your internet connectino). On Windows, use X-Win32 (Caltech provides a copy free to students; see software.caltech.edu). On OS X, download the extra X11 package (should be free). On linux, you're already set.
You can see the runtime options by typing matlab -h. Several useful options:
matlab -desktop use this when you make a shortcut to the program on a desktop (for linux systems) matlab -nodesktop this is not quite the opposite of the previous command. It does what it says: a matlab session is opened up in the console. This is useful is you're working remotely via, say PuTTY, since you can't open XWindows. It's also useful even if you can use XWindows since it can be a bit faster.
If you want a free alternative to matlab, perhaps the most widely used substitude is octave at gnu.org. It is self-described as "mostly compatible" with Matlab.
The current release of Matlab is 2007b (ver 7.5). Recent releases are 2007a (ver 7.4), 2006b (ver 7.3), and 2006a (ver 7.2). All of these are pretty similar, and allow you to use "cell mode" in the matlab editor, which I highly recommend. The unix cluster at Caltech has version 6.0 (Sept 21, 2000), which is a bit out-of-date, but still works. The undergraduate CS cluster might have a version as well. You can see the differences among the versions at this mathworks page.
UPDATE: The versions have been updated twice a year since 2006, so as of this writing, 2009b is the most recent. There have been several significant changes in the past three years, especially with respect to mex files, since 64-bit processors are becoming more common and some of MATLAB's mex API functions were not compatible; search for largeArrayDims for more info.
Other big changes are concerning multi-threading. Since modern processors are trending to have several cores of moderate speed, instead of one very fast core, multi-threading is increasingly important, and the new versions of Matlab are dealing with this better (R2007a is much better than R2006b in this sense). There's also this mathworks platform roadmap which outlines which versions of MATLAB support which platforms.
Editing m-files: matlab's builtin editor works well, especially with the cell mode; it also has tab-completion (same as on the matlab command line). Other popular code-compatible editors, such as emacs, xemacs, vi, vim, winedit, notepad++, etc. should work (and you can configure syntax highlighting, which I highly recommend). For working remotely without XWindows, I run one terminal with matlab -nodesktop and edit m-files with vim on another terminal.
Useful commands are edit for opening m-files, help [command_name] for seeing the documentation for a command, doc [command_name] for the Help Menu's documentation (or, hit F1), lookfor [keyword] if you don't know the exact command name, ![shell command] for using a shell command (note that matlab supports some basic shell commands, such as ls and pwd). what, who and whos give you information about the matlab-related files in the current directory, the current variables, and the current variable with a bit more information, resp.
Advanced practical advice: you can run matlab in batch mode. I think it's matlab -r, but check with matlab -h which gives a list of options. You might want to put an exit command at the end of your m-file, but I'm not sure if this is necessary. If you run it on the unix cluster, use nice so it doesn't hog CPU. And put it in the background by using the & postfix. On a real cluster that uses a queue manager such as the Portable Batch System (PBS), you might not be able to submit matlab jobs directly. Instead, write a short shell script that calls the matlab job, then submit the shell script.
Update for batch mode: you want matlab -nojvm -nodesktop -r filename where you do NOT write filename.m (you might also want the -nosplash option to avoid the splash screen).
Other methods for batch mode. The useful Scientific Computing & Visualization center at BU has this running MATLAB via batch help page. They recommend putting the following into a shell script mbatch:
matlab -nodisplay -nosplash < $1 >! $2
and then run it as mbatch [infile] [outfile] or submit it to a queue.
The $1 and $2 substitute for the first and second arguments to the script,
respectively. The infile should be a MATLAB script (include the .m extension in the name),
and should have an exit at the end of it. For the bash shell, don't include the exclamation mark.
FYI, the >! redirects standard output, like >, but the ! tells
it to overwrite the output file if the output file already exists. However, this only applies
if you are using csh (and tcsh) shell. Other useful redirections: >& redirects both standard output and standard error.
You can combine this with !. You can also append the output to the end of a file,
using >> for standard output, and >>& for standard
output and standard error.
For the bash shell (and Bourne shell family; this is the default on linux),
the commands are slightly different (though as before, the plan > and <
still redirect standard output and input, respectively).
To redirect standard error, use 2> . To redirect standard error to standard out,
use 2>&1 (as you probably guessed, 0 is for standard in, 1 is for standard out,
and 2 is for standard error). >> will append, as in csh. You do not need
to use the ! to overwrite existing files, so be careful not to overwrite accidentally.
See the excellent gudes at the BU SCV center: compiling for the same machine, compiling for another machine that doesn't have MCR. Also, the mathworks help page on MCR.
Page last modified Sep 15, 2009