In Monday'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 Friday - 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.
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:
for
-loop. In general, we want to call such
parts of the script 'Initialization' which is the part where you get your variables into defined states such that you can later work on them.
There are at least three ways to construct a composite string:
filename = ['/path/to/' STATIONAME '.dat'];
filename = sprintf('/path/to/%s.dat', STATIONAME);
filename = strcat('/path/to/', STATIONAME, '.dat');
while
loop.
Not necessarily because it's the best thing to do (in fact, it isn't), we just want you to have used it.saveas
and handing it the figure handle, filename, and optionally a format
defintion it's supposed to use (i.e. if you want colored postscript, add 'psc2' as third parameter).
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!
Here is a list of functions that might be of help.
ronni <at> gi <dot> alaska <dot> edu | last changed: October 08, 2010