University of Alaska Fairbanks
Geophysical Institute

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

2. Fundamental Programming Principles I -- Variables and Data Types

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

Brief introduction on how programming works, what variables and data types are, how to think about them and how you could/should use them.

Lecture

fundamental programming principles (pdf)

LAB 02

LAB: Matlab and Variables

Examples

I give a few simple Matlab scripts and a Shell script as examples for how arrays can be used. The sources are available as tar.gz or zip archive.

Exercises:

1. Review the introductory part on cell arrays and structs in Matlab. Jeff will cover that again next week, but you should be mildly familiar with the concepts as introduced in this lecture. Maybe read the Matlab documentation on that:
> doc cell
> doc struct

online at: struct, cell

2. Understand the "text editor story" by scanning through: http://en.wikipedia.org/wiki/Text_editor. This may seem silly, but it's gonna be one of your most important tools to choose; esp. once you're leaving the Matlab world. A poor choice in that department can make your work less enjoyable. There are many choices!
3. What datatype would be most appropriate for the following values? Think about how you would use the data, most probably you will iterate over some of it, and how you could access it most conveniently (you can use Matlab datatypes):

a)1, 2.3, true, 'c', 'hi there!'
b)Open a terminal window, type

> less /etc/passwd

(type 'q' to exit). Or get an example file here: passwd.txt and open it in a Text Editor.

Think of the ':' as a separator of data fields. How would you store such data? How would you store it if you knew that the first field is a the user name and you wanted to access this field using this information to get all usernames at once? Try to solve the problem on paper without having to worry about reading in the values from the file. We will learn about that later.


ronni <at> gi <dot> alaska <dot> edu | Last modified: February 01 2013 21:41.