Scientific Programming


Michele Furlan

Amount of frontal teaching: 

33 hours

The size of datasets regularly collected by and available to neuroscientists is steadily increasing over time. As a result, programming is becoming an essential skill in order to acquire, clean, transform and extract meaningful insights from the data. This course is intended to provide students with a framework to understand programming, as well as with a set of concrete skills in the field of data science.

During the course we will focus on both basics and advanced topics, such as:
    • What are vectors, matrices, and arrays, and how can we access the data contained in them?
    • How can we efficiently import and export data?
    • How can we visualize data?
    • How can we write our own libraries?
    • How can we optimize the execution of our code?

At the end of this course, and with a certain amount of hard work, you will hopefully be able to:
    • Break down complex problems in smaller discrete components, and then solve the big problem by systematically solving the smaller components;
    • Write clear functions as well as clear libraries;
    • Debug your own code as well as other codes;
    • Combine data acquisition with data analysis potentially in the same set of functions;
    • Be able to consistently clean your code in order to share it with other researchers

The course will last for three weeks, for a total of 33 hours. The lessons will be spent exploring the theoretical as well as the practical aspects of programming.

This course will require the students to complete two exams. The evaluation exam will be taken at the start of the course and will be intended to gauge student’s knowledge of programming. The final exam will be taken at the end of the course and will assess what students learnt from the course. The course will be mandatory for all the students who do not pass the evaluation exam, while it will be optional for students who do pass this exam. The primary programming language used during the course will be MATLAB. Students will be asked to use their own laptop, on which MATLAB will be installed. 

The evaluation exam will take place in Room 005 while all the remaining lessons will take place in Room 003.


21/11/2018: Evaluation exam (10:00 - 12:00)

26/11/2018: 09:00  - 12:00

27/11/2018: 14:00  - 17:00

28/11/2018: 09:00  - 12:00

29/11/2018: 14:00  - 17:00

30/11/2018: 09:00  - 12:00

03/12/2018: 09:00  - 12:00

04/12/2018: 14:00  - 17:00

07/12/2018: 09:00  - 12:00

10/12/2018: 09:00  - 12:00

11/12/2018: 14:00  - 17:00

21/12/2018: Deadline Final Exam

The evaluation exam will cover theoretical aspects (e.g., what is a function, what is a loop) as well as exercises in MATLAB (e.g., matrix multiplication, indexing, control flow). In the final exam students will be asked to write a simple script to run an experiment and collect behavioral data. Students will have the last week of the course to complete the final exam independently, and will be asked to submit it by the final day of the course. The goal of the final exam is to help students see what they have learnt in the course, and which areas they may still want to improve.

Lesson Plan

Lesson 1A: Programming basics
Here we will focus on what we mean by programming, and why programming is becoming increasingly important for scientific research. We will learn what MATLAB is, how to use it (e.g., using the command window, Workspace, and command history), and where to find help, including the online resources available (e.g., “Loren on the art of MATLAB”) and documentation from Mathworks (manuals).

Lesson 1B: Data fundamentals 1

Here we will focus on numerical data (e.g., int, double) and how to combine them in vectors, matrices, and arrays. At the same time, we will explore how to access the data using indexing, matrix manipulation, matrix combination, subsetting, variables, assignments, incrementing and decrementing.

Lesson 2: Data fundamentals 2
Here we will focus on other data types, such as characters and strings, and how to manipulate these data types. We will explore concepts including string manipulation, arrays, structures, cells, and dynamic access. We will also learn how to import several types of data and how to tidily store them.

Lesson 3: Exercises on data fundamentals

Lesson 4: Loops
Here we will focus on loops, such as for, if, while, switch, break, return, nested loops, conditional statements (and, or), flow controls. We will also explore how to reduce the number of loops by vectorizing our code.

Lesson 5: Functions
Here we will learn how to write functions. We will learn about nested functions, function handles, the difference between scripts and functions, debugging, error handling (try-catch-end), input, output, and libraries.

Lesson 6: Data visualization
Here we will learn how to visualize our data as a function of our purpose (e.g., fo publications, or a sanity check). We will first focus on simple plots, such as line and scatter plots, and then move on to more complex topics, such as 3D plots, line properties, subplots, figure handles, displaying images, printing plots, and meshes. We will also learn how to import images (e.g, *.bmp) and how to save your images.

Lesson 7: Data I/O
Here we will focus on data importing and exporting. This will include how to import and export data with different file formats (e.g., *.txt, *.xls, *.bmp.

Lesson 8: Advanced topics
Here we will understand how to effectively clean your code (although this concept will be emphasised during the whole course). We will focus on topics such as vectorization, timing optimization, memory handling, preallocation and initialization, producing a log, naming, speeding up your code by writing in C++ (creating mex files), and writing your own libraries.

Lesson 9: Exercises on data I/O and advanced topics

Lesson 10: Psychtoolbox
The final part of our course will be spent learning how to create stimuli, visualize stimuli, wait for responses, collect response time and accuracy data, and build an experiment.