Matlab Area for the local group
What is MATLAB?
MATLAB is an interactive, matrix-based system for scientific and engineering calculations. You can solve complex numerical problems without actually writing a program. The name MATLAB is an abbreviation for MATrix LABoratory.
Where can I get MATLAB help?
MATLAB is among the most convenient ways to do linear algebra,
time series analysis, and data analysis in general. No matter
you want to do, MATLAB is probably your best bet (by the way I'm not paid
or sponsored by MATLAB).
There are a number of ways you get an answer to your MATLAB question;
If you know the exact command you are seeking help about, type help command
If you are not sure what the command you are looking for is, but know a keyword about it,
type lookfor keyword
|
Q: How do I find out about plotting a y vs. x figure? A: help plot
Q: How do I find out about making a contour plot? A: help contour
Q: How do I find out about doing some statistics? A: help stats
Q: How do I find out about plotting coastlines and continents? A: help map
Q: How do I find out about ??? ? A:help ??? or lookfor ???
|
The MATLAB's demo feature, which leads you through some of MATLAB's features
The MATLAB manuals in the unix room
ask me!
|
Online help:
A brief list of the most basic MATLAB commands
Some Basic Commands (Note command syntax is case-sensitive!)
matlab loads the program matlab into your workspace.
help accesses the comprehensive help area
quit quits matlab, returning you to the operating system.
who lists all of the variables in your matlab workspace.
whos list the variables and describe their matrix size.
clear deletes all matrices from active workspace.
clear x deletes the matrix x from active workspace.
... the ellipsis defining a line continuation is three
successive periods.
save saves all the matrices defined in the current
session into the file, matlab.mat.
load loads contents of matlab.mat into current workspace.
save filename saves the contents of workspace into
filename.mat
save filename x y z
saves the matrices x, y and z into the file titled
filename.mat.
load filename loads the contents of filename into current
workspace; the file can be a binary (.mat) file
or an ASCII file.
! the ! preceding any unix command causes the unix
command to be executed from matlab.
Let's get going:
Download the tar file: matlabdir.tar to
your /home directory (ie. I would want to see /home/rwardle/matlabdir.tar).
untar the file: tar -xvf matlabdir.tar
type cd matlab, and then ls -l, you should see:
bin - Directory containing matlab utility scripts that,
hopefully, will never need changing
data - Directory containing conmap and netcdf files used
by the matlab scripts in the examples dir
examples - Directory containing example matlab scripts
startup.m - The file startup.m specifies startup options.
You can modify the default search path, predefine
variables in your workspace etc.
cd bin
ls -l gives
rcmp.m - Function script to read in a conmap file
cd ../examples
ls -l gives
conmapexample.m - script that reads in a conmap file
and contours the data
datacdfexample.m - script that loads in a netcdf NCEP data
file and displays a field.
cd ../data
ls -l gives
T2M.33.DJF.cmp - conmap file used by conmapexample.m
ncep.cdf - netcdf file with NCEP data used by datacdfexample.m
cd ..
matlab - invoke matlab with a graphical user interface (gui)
matlab -nojvm - invoke matlab at the command prompt (my preference)
You will now see the matlab prompt: >>
|
MATLAB paths:
For matlab to run a script, matlab must be able to see it.
That means you either 1) have the matlab workspace in the script's directory
or 2) have the script in a directory that is in your matlab path.
The second option is the best as you end up with all of your scripts together,
you don't lose them and you can catalogue them more easily.
To set up your matlab paths, you need to add lines to your startup.m file:
addpath /home/rwardle/matlab/examples
etc.
Here, we have added a dir to the matlab path so we
can invoke the .m files that are located there from any directory, say where the data
files are located.
A users default matlab path is /home/username/matlab so this
doesn't have to be set.
Examples
1. Loading conmap files
>> cd ~/matlab/data
>> conmapexample
The matlab script conmapexample.m (in dir ~/matlab/examples)
loads and displays data contained in the conmap file T2M.33.DJF.cmp
The conmapexample.m script calls rcmp.m
(in dir ~/matlab/bin (which is in the default path)) which reads in the
conmap file (headers and all) and returns the array and renames it
(to t2m in this example). It then does a simple contour plot.
In theory you should never have to modify the rcmp.m script.
You just need to call as is shown in conmapexample.m, ie. you need
to specify it's name and dir path.
|
2. Loading netcdf files
|
This is easy!! All you have to do to load in a netcdf file is type >> ncload filename or >>ncload('filename').
As an example of loading in data from a netcdf and then manipulating it to produce a
plot see netcdfexample.m
|
3. Defining functions, plotting, time-series analysis
|
Check out demo_time.m in dir (~/matlab/examples)
|
4. Computing quantities as a function of space and time and plotting
|
Check out demo_insol.m in dir (~/matlab/examples)
|