Name:______

Introduction to Matlab: A first glimpse at new data

This activity will introduce students to a few basic functions and techniques to load data and plot it using Matlab. An evenly interpolated data set is provided, but any data set could be substituted for this exercise, and may make the assignment more challenging. The for-loop can be modified to iterate through any of the continuous variables. This data set consists of modern-age (average from 6-0 ka) benthic carbon isotope measurements from 177 core sites in the Equatorial Atlantic (spanning 30N-30S). The text file 'EqAtl.txt' consists of latitude, depth (meters), and modern d13C in columns, of 177 sites in rows. The Matlab code students will edit is called 'Matlab_Intro_student.m', and it contains commented (%) annotations and instructions. Below are brief instructions.

Instruct students whether they should answer questions in this document, after "Code:" or within the '.m' file in comments and publish the script as a .pdf (I would recommend the former and ask students to embed the .png figure in this document, then export it as a .pdf or save as a .doc.

General advice:

  • Google things. If you run a script, and get an error message, copy and paste that message in Google. Chances are you aren't the first student to be confused by the things Matlab tells you, and the answer exists in a Matlab forum or help page, or elsewhere on the internet.
  • Make comments and annotations. Use the '%' sign to comment out words and make notes next to the code so when you go back and read your script months after you last worked with it, you can remember what you were doing. I also try to date my code, especially if I'm editing/fixing/debugging things. When you're editing a work in progress, copy the broken code, comment out the first version, and work on the copy so you can keep track of where you started, what works, and what doesn't while you're fixing things.
  • Work through one line of defective code at a time.
  • If you're really stuck, step back and write out what you're trying to code or fix on paper with words and symbols, but more words, until you get a better idea of what to try/change.

·  Google your problem or situation, there's a lot of information on the internet, and lots of reputable Matlab forums to post questions and get great answers from experts.

Open 'Matlab_Intro_student.m' with Matlab. Make sure the data file 'EqAtl.txt' is in the same directory (folder) as the Matlab script (.m file).

First load the file 'EqAtl.txt', and name that variable 'data', unless students are using their own data set.

Code:

What are the dimensions of 'data'? How did you find it?

Code:

Name the variables for latitude, depth, and modern d13C. Transform the depth column from meters to kilometers.

Code:

______

Optional step: interpolation. If you're using a different data set with data that is unevenly spaced, you can linearly interpolate that data onto an evenly spaced sequence with the function interp1. The data set 'EqAtl.txt' has a latitude, depth, and modern d13C value for each core site (no not-a-number or missing values), so there is no need to interpolate those data.

______

For loop

A for loop is a neat way to iterate or loop through a continuous data set, like a time series data set, or this 177-site Equatorial Atlantic carbon isotope data set. With this 'EqAtl' data set, we want to plot the data in different marker styles and colors for depths above and below 2 km. In the example provided, we will use a for loop to step through each core site in the data set, and an if statement and else statement to select data based on its depth, executing a plot funtion with one color and marker style for sites shallower than 2 km, and different styles for sites deeper than 2 km.

Most of the code for this for loop and plot are provided, but it needs to be edited to satisfy the above requirements, also commented in the script:

%Below, fix the code so the data shallower than 2 km depth plots as a black

%square and the data deeper than 2 km plots as a red diamond.

Code:

After you're satisfied with the figure produced by your edited for loop, save the figure as a .png file, and embed the figure in this document below. Then save this document as a .doc and a .pdf for submission.

Figure: