University of Alaska Fairbanks
Geophysical Institute

Beyond the Mouse 2010 - The geoscientist's computational chest.

Lab 6: Matlab I/O 2

"Programming is legitimate and necessary academic endeavor."
Donald E. Knuth

Lab slides

none.

Exercise 1: (no solution, that's stuff you gotta do on your own)

Download these two files and store them in the same directory:

Execute the script such that the figure appears on your screen. It looks a little weird with spikes; kinda like a random fence. We'll take care of that later. For now, I want you to discover the properties of the figure/axes you can change with the property editor: in the figure window menu go to 'edit'->'axes properties' and/or 'figure properties'. Try to find a button that says 'More Properties'; change things and see what happens. Take note of the respective names of the properties; they are similar to what you would use as parameters. Also try adding a title, and labels for x and y axis. in get/set.

Exercise 2: (Solution (figures 1 and 2))

Now we're getting a little more serious; the data as displayed in your figure is plain wrong. We've got to correct for this and make things look nicer. If you check line 5 in fai_temp.m you will see that I plot temps over dates where dates is a vector that holds the dates of temperature measurements in the format 'YYYYMMDD'. Matlab does not know anything about you using dates for the x-axis and assumes dates contains integer values. This is where the weird spaces in your figure come from: we have big gaps from 19801231-19810101, 19811231-19820101, and so on. Matlab assumes those could be legal values and reserves space on the x-axis. That's not wrong and also not too bad, but plot by default connects all data points with a line. Hence it appears you have data where there is none.

Let's fix this! Matlab's internal representation of times is using serial date numbers. Instead of using dates as given in the original file, let's do this:

You might notice that the tick labels are in strange places. Let's try having them every 5th year. There are many ways of doing this. Here is one:

Alright. Now YOU know that your x-axis tick spacing is 5 years, but it's not really obvious in the figure. We should change the tick labels!

Great, now that we know what we're dealing with we can add title, x, and y labels. I recommend you to use '\circF' as part of your ylabel argument to clarify that temperatures are in degrees Fahrenheit.

If you want to get a better idea about how the temperature evolved over this long time, you could smooth it using a moving average approach over a period of 365 days:

Your final figure should look similar to this:
Fairbanks Intl Airport Temperature data, example

Exercise 3: Setting axes (Solution (Figure 3))

Now, with very few steps you can add a lot of extra information to that figure. Let's add a spectrogram. Here's what I want you to do: Your final figure should look similar to this:
Fairbanks Intl Airport Temperature data, spectrogrma, example

Helpful Matlab Functions:

Here is a list that might be of help.

ronni <at> gi <dot> alaska <dot> edu | last changed: December 27, 2010