Summary and Schedule
The best way to learn how to program is to do something useful, so this introduction to MATLAB is built around a common scientific task: data analysis. Our real goal isn’t to teach you MATLAB, but to teach you the basic concepts that all programming depends on. We use MATLAB in our lessons because:
- We have to use something for examples;
- It’s well-documented;
- The user base among scientists in academia and industry is large and continues to grow; and
- It has a large library of packages available for performing diverse tasks.
But the two most important things are to use whatever language your colleagues are using, so that you can share your work with them easily, and to use that language well.
Introductory slides
The introductory slides, shown at the beginning of the session, contain a lot of useful links, including the feedback form.
GNU Octave
GNU Octave is a free and open-source alternative to MATLAB which shares its syntax (see more about compatibility). Thus, if you don’t have access to MATLAB, you can easily set up Octave on your computer and still work through the lesson.
Prerequisites
To begin tackling this lesson, you will need to:
- Understand the concepts of files and directories, and the concept of a “working directory”.
- Know how to start up MATLAB, and access the command window
(which generally has a
>>
prompt). - Know how to create, edit and save text files.
Overview of the data
We are studying inflammation in patients who have been given a new treatment. Our dataset is divided in 3 groups:
- The base group consists of 12 files containing a base study of inflammation after a surgery without any new treatment.
- The control group consists of 6 files containing the data for patients that were given a placebo.
- The test group consists of 6 files containing the data for patients that were given the new treatement.
In the files, each row holds information for a single patient and the columns represent successive days.
The actual data sets do not have titles for columns or rows. The data
is stored in Comma
Separated Values (CSV) format. This means that values in a single
row are separated with a ,
. The first few rows of our first
file, data/base/inflammation-01.csv
, look like this:
0,0.065,0.169,0.271,0.332,0.359,0.354,0.333,0.304,0.268,0.234,0.204,0.179,0.141,0.133,0.115,0.083,0.076,0.065,0.065,0.047,0.04,0.041,0.028,0.02,0.028,0.012,0.02,0.011,0.015,0.009,0.01,0.01,0.007,0.007,0.001,0.008,-0,0.006,0.004
0,0.034,0.114,0.2,0.272,0.321,0.328,0.32,0.314,0.287,0.246,0.215,0.207,0.171,0.146,0.131,0.107,0.1,0.088,0.065,0.061,0.052,0.04,0.042,0.04,0.03,0.031,0.031,0.016,0.019,0.02,0.017,0.019,0.006,0.009,0.01,0.01,0.005,0.001,0.011
0,0.081,0.216,0.277,0.273,0.356,0.38,0.349,0.315,0.23,0.235,0.198,0.106,0.198,0.084,0.171,0.126,0.14,0.086,0.01,0.06,0.081,0.022,0.035,0.01,0.086,-0,0.102,0.032,0.07,0.017,0.136,0.022,-0,0.031,0.054,-0,-0,0.05,0.001
We want to explore and analyse this data, and for that we will need to:
- Load that data into memory.
- Make operations with the data.
- Visualize the processed data.
To do all that, we’ll have to learn a little bit about programming.
Setup Instructions | Download files required for the lesson | |
Duration: 00h 00m | 1. Working With Variables |
How can I store values and do simple calculations with them? Which type of operations can I do? |
Duration: 00h 50m | 2. Arrays | How can I access the information in an array? |
Duration: 01h 30m | 3. Loading data | How can I load data to an array? |
Duration: 02h 10m | 4. Plotting data | How can I visualize my data? |
Duration: 03h 10m | 5. Writing MATLAB Scripts | How can I save and re-use my programs? |
Duration: 03h 45m | 6. Making Choices | How can programs make choices depending on variable values? |
Duration: 04h 25m | 7. Creating Functions |
How can I teach MATLAB to do new things? How can I make programs I write more reliable and re-usable? |
Duration: 05h 30m | 8. Repeating With Loops | How can I repeat the same operations on multiple values? |
Duration: 06h 20m | Finish |
The actual schedule may vary slightly depending on the topics and exercises chosen by the instructor.
Setting up MATLAB
You will need to install MATLAB or GNU Octave to do this lesson.
If you cannot install either of these, you can use MATLAB Online. It is free to use, but you need to set up an account.
You will also need to download some data, which we will analyze using MATLAB:
Download matlab-novice-inflammation.zip and move the file to your Desktop.
Extract the zip archive. This will create a
matlab-novice-inflammation
directory containing the data files used in the lesson.