GEOS 597e Spatiotemporal Data
Analysis Workshop
Homework 0: Get ready, get
set
Get set up for computing in a Matlab/PC environment, from the CLUE
Lab's PC workstations.
Last
updated 8/23/06. To be completed prior to class
session Weds., Sept. 30th.
0.
Introduce yourself. Send me email from the
account you would me to use for course communications. The email
should have subject line "STDA: [your name]" with the following
information in the body of the message:
0.1. Your name, and how you like to be called.
0.2. Your department, degree sought, major, and minor.
0.3. Your thesis topic.
0.4. Your familiarity with Windows and Matlab, each on a scale of
1 (none) to 10 (fluent).
0.5. A list of courses taken (and when) in relevant subjects such
as climate dynamics, linear algebra, geostatistics, and computer
programming.
0.6. Why you are taking this course, and what you hope to get out
of it.
For example your email might look like:
From:
wilma@geo.arizona.edu
Subject: STDA: Wilma Wildcat
Wilma Wildcat
("Wil")
Geosciences,
Ph.D., Geosciences, Global Change.
Thesis topic:
Paleoclimatology of the Football Stadium region of southern Arizona.
Familiarity with
Windows: 9; with Matlab: 2.
Courses taken:
Math 215 (Linear Algebra), Spring 2003; Atmo 595b (Climate Change),
Fall 2003.
Why I'm taking
this course: I want to interpret my own datasets using the techniques
covered in this class.
1. Get CLUE
lab access. Get a swipe card, door combination, userid and
password to access computers in the CLUE Lab, Geosciences Dept., Gould-Simpson
Bldg. Rm. 228, by contacting Eneida
Lima, CLUE Lab Manager, Gould-Simpson Rm. 542. Eneida will be in class Weds. Aug
23rd, 1:30pm, to have you sign forms, etc. to do all this if you haven't
already. Read the CLUE
Lab rules.
2. Meet Matlab on Windows.
Log into a PC workstation of your choice. Start Matlab by
clicking on the desktop icon labeled "MATLAB R2006a". After a long
while, you should get the Matlab startup screen, which looks something like this screenshot from
my linux box:

There are five important sections to the matlab desktop:
On the right is the command window,
into which you (not surprisingly) can enter matlab commands. but also
you can pass commands to Windows by preceding them with an exclamation
point. For instance, execute the following command at the prompt (>>):
>> !cd
\"Documents and Settings"
>>
!mkdir stda
This will create the directory stda in the
named directory. Now click on the button labelled ... just
above the command window. You can then change directories to the stda
directory you just created. Files you subsequently save from
matlab will save here (and importantly, be available to you here) when
you log back in next time.
The window on lower left of the matlab
desktop is the command history. Notice that the commands
you typed have appeared here. This is helpful for keeping track of
where you've been and what you've already done. An even more
important feature: notice that pressing the up arrow in the command
window gives you the previous command you entered. This is
immensely useful for avoiding typing mistakes, one of the biggest
sources of coding bugs. Also, notice that typing the first few
letters of a command, then the tab key, gives you a menu of possible
word completions, from which you can select by double clicking on
one. It will appear on the command line.
The upper left window shows the
working directory structure, something like "Explore" when you
right click on the Windows Start menu. This helps you organize
your work. By clicking on the "Workspace" at the bottom of this
window you can alternately view the variables and their dimensions in
memory. Speaking of variables, let's create one by typing in the
command window
y=randn(1000,1);
What does this do? To find out how a matlab command or function
works, try typing
>> help
command
replacing command with the matlab command or function of
interest. For instance:
>> help more
gives the following result:
>> help
more
MORE
Control paged output in command window.
MORE OFF disables paging of the output in the MATLAB command window.
MORE ON enables paging of the output in the MATLAB command window.
MORE(N) specifies the size of the page to be N lines.
When MORE is enabled and output is being paged, advance to the next
line of output by hitting the RETURN key; get the next page of
output by hitting the spacebar. Press the "q" key to exit out
of displaying the current item.
Reference page in Help browser
doc more
>>
Try it out: type more on,
then ask for help on randn. The purpose of the help command is to
show you how a function is called (the syntax); what arguments it takes
(the values or parameters in the parentheses on the right hand side of
the command structure, and the output it returns (the variables in the
left hand side of the function syntax.
Now bring up the editor window:
>> edit test.m
You'll get a new window called test.m. Let's make test.m into a script: a set of
instructions for doing some work for us. In our script type the
following commands:
clear
y=randn(100,1);
x=1901:2000;
You now know how to find out what each of these commands does, so go
ahead and investigate these functions. While you're at it, in the
command window type
>> help
/
to find out about how to add, subtract, multiply, divide, and compare
relational values (relops).
(The helpdeskis a much fancier
way to explore matlab's functions, including demonstrations, tutorials,
and examples. Check it out, especially if this is your first
experience with matlab, but also to see what new features may have been
added since you started working in the environment.) For more
about online help, including the very useful lookfor command,
see next week's prework reading, section
3.4.
You'll see the variables x and y appear in thw workspace as a vector
with 100 elements, organized as a row vector (something we'll learn
about next week in more detail). In the command window you can type
>> x
to see the values in each element of the row vector x;
similarly, for y.
What happens when you type
>> x;
? Use the semicolon in your script commands to avoid typing
the result of every last command out to the command window, which may
slow your script down by a factor of ten or more.
To plot values we call up a figure
window by adding to our script
plot(x,y,'o-')
and to save a copy of the plot we can type
print -deps
f1.eps
or
print
-djpeg100 f1.jpg
You can save a copy of the work your script has made either by adding
save
testwork.mat
and/or
save -ascii
xy.dat x y
to your script test.m, which should now read:
clear
y=randn(100,1);
x=1901:2000;
plot(x,y,'o-')
print -deps f1.eps
print
-djpeg100 f1.jpg
save
testwork.mat
save -ascii
xy.dat x y
Save your script in the editor window. Now in the command window
type
>> test
to run your script. This is essentially how you will develop your
codes for EOF analysis and singular spectrum analysis over the semester,
and to graphically display the results.
3. Comment my code. Copy
and paste the following script into an editor file; call it synt.m.
Your task is to familiarize yourself with the commands called in this
script, and to comment the script to explain what each line does.
What does the code do overall? Put this comment at the very top of
the script. Remember, to paraphrase a librarian friend of mine:
good commenting is like sex: when it is good, it is very very good; and
when it is bad, it is still better than nothing at all. You can
comment a line (or the remainder of a line) by starting it with the
percent sign, %.
In your classwork scripts you won't need to comment every last basic
matlab function call, but you will want to comment sections of your code
to explain to yourself and to me what you intended to do.
% script
synt.m: here is a line to
replace with a real comment
clear % this command clears all variables from memory when the
script is called
nt=1000
r1=0.4;
t=1:nt;
e(1)=randn(1,1);
for i=2:10*nt
e(i)=r1.*e(i-1)+randn(1,1);
end
e=e(length(e)-999:length(e));
v1=var(e);
v2=e*e'./(nt-1);
[v1 v2]
y1=randn(1,nt);
y2=sin(2*pi*t./20);
y3=t./1000;
y4=(t-mean(t)).^2/1000^2;
y4=y4-mean(y4);
y5=ones(1,1000).*4;
y=y1+y2+y3+y4+e+y5;
subplot(211)
plot(t,y)
set(gca,'Fontname','Times','Fontsize',16)
title('plot of Y vs. T')
xlabel('time(years)')
ylabel('amplitude (no units)')
grid
axis([0 1000
-2 12])
subplot(212)
plot(t,y)
set(gca,'Fontname','Times','Fontsize',16)
title('plot of Y vs. T')
xlabel('time(years)')
ylabel('amplitude (no units)')
grid
axis([0 100
-2 12])
print -deps
synt.eps
print
-djpeg90 synt.jpg
save
syntwork.mat
4. Deliverables. Send me
the email requested in part 0, and print out and turn in your commented
script from part 3 of this classwork.
Back to Schedule/Syllabus.