University of Alaska Fairbanks
Geophysical Institute

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

Lab 4: Matlab Flow Control

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

Lab slides

flow control, functions (pdf)

Introduction

In this week's lecture we introduced constructs that allow you to increase the complexity of problems you can solve with your programs. Flow control language features like if-else, for, or while allow you to create tree like structures of code rather than one long list of function calls. Great! Today you'll expand the problem we worked on last week - the GPS time series. The goal is to have you create a Matlab script which will process a bunch of data files: load data, put it in an array of structs, create figures.

Exercise (Commented Solution)

You will use the data from last week. Download this archive (zip) to get the data files and necessary functions. Let me write out in detail what I expect you to do:

If you are done early, consider this: textread will complain (throw an error) if a file does not exist. Given that you might be dealing with hundreds of stations at a time it would be frustrating to stop possibly lenghty processing whenever there is a typo in the cell array that holds the sites or certain files are just not there. Guess what: try-catch will help!

Try putting the read_gps_data function call in a try-block and catch possible errors. Give a useful error message (consult last lectures introduction of the try-catch-block and the respective documentation pages for information the error message gives you) OR display your very own error message, i.e. file X does not exist, where X is the parameter you handed to read_gps_data. Then add a fantasy string to the cell array that holds the station names and run your script. You should get at least one empty plot and a meaningful message, but the script should not abort - yeah!

Helpful Matlab Functions:

Here is a list of functions that might be of help.

ronni <at> gi <dot> alaska <dot> edu | Last modified: October 14 2011 23:13.