Materials and exercises from the Introduction to Matlab Programming course which forms part of our MSc Cognitive Neuroscience.
For viewing the materials use: https://schluppeck.github.io/learningMatlab/
For inspecting the code and details: https://github.com/schluppeck/learningMatlab
Create a (free) account at The Mathworks. Using your university e-mail address will allow you to use the university’s academic license. As an added bonus, you’ll be able to install Matlab on your own computer / laptop (MacOS, Windows, or Linux)
There is a self-directed Matlab onramp course that we will refer to during the course. This includes some short videos and interactive lessons, which we will use to flip the classroom.
We’ll ask you to complete this onramp course. The sections should’t take too long complete and there are lots of hints to guide you through the material at your own pace.
The first place to check out is the aToZ-intro. Run through these exercises on the lab machines (or on your own copy of Matlab).
Find PDF materials in one place in the matlab primer [PDF]
Lecture slides for sessions 1-4:
The main aims is to help the students to get to grips with the basic ideas of computer programming and, more specifically, the use of Matlab. The course materials started out for a graduate course for psychologists and neuroscientists.
The exercises draw on material that students on our MSc courses encounter in other modules. It’s therefore a great opportunity for hands-on revision of some important concepts such as
The syllabus is for a 10 week (10 x 2h) lab class, assuming very little computer experience (or maths) at the start.
Feel free to use the code. If you feel it’s particularly helpful to you… I accept donations in the form of freshly roasted coffee beans.
The course has two chunks. (Schluppeck has been tinkering with the course more recently and we’ve also done a different project around stimulus presentation.
an introduction to the basic ideas (variables, functions, control flow) - running over the first 4 weeks. Check out the material in the aToZ-intro folder and the associated readme file here.
Timetable A. A project, building some basic utilities / functions for looking at neuroimaging data and performing linear regression (GLM), 6 weeks. Details on the imaging-related units is outlined in here.
Week | Unit | Topic |
---|---|---|
1 | aToZ-intro | What is Matlab, the environment, variables, indexing, … |
2 | aToZ-intro | Types of data: numeric, logical, text, etc. |
3 | aToZ-intro | Indexing, looping, branching, functions, … |
4 | aToZ-intro | Understanding someone else’s code |
5a | imaging-00 | What are images? How to display them |
6a | imaging-01 | Building / fixing up a simple image viewer |
7a | imaging-02 | A function that constructs a simple design matrix |
8a | imaging-03 | Hands-on linear regression (using a sample timecourse) |
9a | imaging-04 | Doing regression stats, displaying |
Assuming you are on a Mac: open up a Terminal
(double-click /Applications/Utilities/Terminal). Then do the following:
# if you don't already have one: create a ``matlab`` directory in your home space (``~``), then change directory to it:
cd ~
mkdir matlab
cd matlab
# get MGL (for the behavioral project)
git clone https://github.com/justingardner/mgl.git
# get these tutorials
git clone https://github.com/schluppeck/learningMatlab.git
You’ll need to add both these subfolders to your path; then you should be good to go. A convenient way to do this is to run this or add this to your startup.m
file:
addpath(genpath('~/matlab/'))
To make sure you have any updates to this material, open a Terminal, change directory to the learningMatlab
folder and issue git pull
. This will sync you the material on github. Alternatively, download the zip archive of the repository.
The sections should’t take too long complete.
In the 2015/2016 iteration of the course, I modified the hands-on project for building a simple behavioural task to use mgl (https://github.com/justingardner/mgl). Although this requires teaching a couple more details on how stimuli are being displayed by the OpenGL machinery and it’s not pure Matlab, it’s (a) more realistic and (b) makes displaying different kinds of stimuli, obtaining keyboard responses, etc. much more fun and doable.
In the 2017 iteration, students built a psychophysical experiment (slightly different task, but similar in spirit)
In 2018, the assignment for the course was complete and extend an analysis script for fMRI data by writing some helper functions. Students were also using publish()
to explore documentation and mixing code with report writing.