Introduction to Matlab: A first glimpse at new data

Carlye Dian Peterson
University of California-Davis,
Author Profile


Introduction to Matlab: A first glimpse at new data. The purpose of this exercise is to familiarize students with basic Matlab functions and techniques so they can load and plot data. With this lab exercise, students will learn to load data, name variables, and pre-process so the data can be plotted. Students will learn how a for loop and if statements can be used to plot different parts of a data set in different colors and marker types. This assignment can be used in any computation or science class using Matlab as an early activity to introduce students to Matlab and a few basic techniques to load and plot data.

Learning Goals

From this activity, students will learn basic Matlab functions such as load, size, scatter, and how to transform data using arithmetic, and how to select different parts of a data set using a for loop and if statements. This activity provides an introduction to Matlab its self, but also tequiniques for having a first look at data. Students will complete the Matlab code to name variables and correct code in a for loop to plot data. The only "original' code students must come up with is how to query the size of a variable. This low-level committment to coding ensures that students with little computation experince will not be turned off by such an activity. Students are required to provide their code within the accompanying instructions document which can be modified to include short answer questions about the data its self or the Matlab code.

Context for Use

Students will need access to Matlab to complete this assignment. This activity is designed for undergraduate or graduate students to use Matlab to have a first look at any data set, whether for their own research, or practicing with the simple data set provided. This assignment is meant to be completed by students during a lab section or as a homework assignment after a lecture on the basics of Matlab. A follow-up lecture to reinforce and build on concepts is recommended so students can practice what they have learned. Later assignments will rely on the functions and techniques practiced in this activity. This introductory activity could be adapted for any class as an introduction to data analysis with Matlab.

Description and Teaching Materials

A full description of this activity is included in the attached file, "Intro_Matlab_student.doc". In this activity, students will learn the basics of loading data into Matlab and plotting a portion of the data using a for loop.
Introduction to Matlab student handout (Microsoft Word 20kB Oct5 16)

Teaching Notes and Tips

If students are working with their own data, they may need individual instruction on how to pre-process their data so it can be plotted and analyzed.


Students should "publish" their edited Matlab code to a pdf file or copy their code into the instruction document ("Intro_Matlab_student.doc") and embed a .png of the figure. Teachers can check students code and how they answered questions and assign points as they see fit. There are four "code:" spaces for students to fill in and one figure to embed in the instruction document. If students have completed the activity successfully, the published file will include a figure (or embedded in the instruction document) which should have a y-axis in kilometers (check the numbers, the label name is hard coded), black squares for data shallower than 2 km, and red diamonds for data deeper than 2 km.