Introduction

This guide is an attempt to make learning Matlab as painless and intuitive as possible. And maybe even a little humorous. The current Matlab 101 books tend to go the same route, starting with the basics of mathematical operations and then building upon them with mind numbing examples of magic squares. Seriously, check out the table of contents of a few beginner Matlab books and they are nearly all identical. No more magic squares I say! I plan for this guide to be different from others in a few ways which I hope will facilitate learning and understanding how to program in Matlab. 

Magic square matlab
Example Magic Square. Source.

 

0) It’s free! This guide will always be free for everyone. Note, Matlab the program is not free. If you are at a university, student or staff, you should be able to get it for free/discounted through your university’s or department’s software license program. Otherwise you will need to buy an annual subscription to Matlab. If you are looking for a free programming language I recommend Python.  

1) I’m going to assume you have never opened Matlab before. I’ll walk you through how to setup the Matlab interface, deal with setting “the path”, how to save your work, and other practical things that are often omitted from guides but many people learning Matlab struggle with. 

2) There will be errors! This guide may be the only one that will purposefully cause you to make errors. Dealing with errors in Matlab (and computer programming in general) can be very difficult. Error messages are often poorly worded and hard to understand without a background in programming. I’ve found students often get very frustrated with errors and moral takes a hit. Furthermore, without someone there to ask in person about some errors it can be challenging for a beginner to diagnose errors through googling. Here we are going to purposefully make errors so we can understand them and later you will be able to deal with them in your own projects. 

3) A unique work flow. As I pointed out earlier, if you look at the table of contents of many Matlab 101 books they are nearly identical, e.g. 1) Arithmetic 2) Variables 3) Functions 4) Linear algebra.. etc etc. While this order of learning is certainly logical to build up Matlab knowledge, I find it dry and boring. We’re just going to jump right in to doing real programming and learn all this stuff organically. Ideally this will facilitate learning and retention of Matlab concepts. 

4) No more boring examples.* All the examples in this guide, I hope, will be practical exercises that can help in the lab generally and/or they will use real data that I hope you find interesting. For example, this guide does not start with learning how to add and subtract in Matlab. Rather, right out of the gate you will learn to program a trial randomizer which can help you setup experiments regardless of your scientific field. However, there are certainly complex analysis methods that more in-depth, discipline specific Matlab guides can help with. This guide is only meant to be a general overview of programming in Matlab.

* The best way to learn computer programming is to work on your own projects to solve your own problems; be it to analyze data or autonomously water your plants. This advice was given to my by programming wiz Dr. Ben Kraus in my undergrand lab who, after completing his PhD, went on to work at Matlab (so he probably knows what he is talking about). Learning Matlab through guides and their examples can cause many people to quickly lose interest and in turn hinder learning. However, you need to start somewhere and I hope this guide aids you in getting a Matlab foothold so you can start on your own projects as quickly as possible with a foundational understanding of Matlab.  

 


Table of Contents

Chapter 0.0: How to setup Matlab

Chapter 0.1: Reagent calculator

Chapter 0.2: Trial randomizer