top of page

Matlab Basics

When you start learning to computer-program, watch tutorials and read books. Learning to program is like learning any other language, such as Spanish. It takes a while. I list here 5 fundamentals you want to learn early to program in Matlab. Many beginners struggle with variable types and classes and how to manipulate them. Tackle the challenge head on! Check out MATLAB challenges for beginners after you familiarized yourself with the MATLAB basics.

1. Variable types, classes, and other basics

You need to know the different variable types and classes. What is and how to handle a ...

  • String, Char

  • Integer, double, single

  • Logical

  • Boolean

  • Matrix

  • Vector, array

  • Cell

  • Struct

  • Function

  • if/else/elseif statements

  • for/while loops

Fundamental Matlab classes are described here and here.

2. How to manipulate types and classes

You will also need to know to manipulate the variables and data types. How to access elements of a matrix/vector/cell/struct/string? How to concatenate, add, replace, append, reshape data? For this you need to about how to use the different brackets/parentheses types in different contexts: (), [], {}

This seems to be a good starting point. A good book to learn is Matlab for Behavioral Scientists.

3. Logical indexing

Logical indexing is a very powerful way to manipulate data in Matlab. This is one of the things you would want to learn early. It is closely related to point #2. Matlab provides a good tutorial on logical indexing. Read more about it.

4. Plot data!

Learn early on to plot data (i.e., use the "plot" function). This will help you to quickly identify errors in your analysis pipeline and will help you to understand your data. Good data scientists always plot data to get a sense and confirmation of their data analysis.

5. Help, Google, LLMs

Programming is, probably up to about 70%, knowing what exists. For example, matlab has an in-build function to calculate the mean of the numbers in a vector (called "mean"). Matlab also has an in-built function that provides you with the size of a matrix (called "size").  There are thousands of such functions, and it would be crazy for you to program them again. Use what exists.

 

Use google to find what exists. Use the help function in Matlab to figure out how to use a specific function (e.g., the mean or size functions). Programming is problem-solving. Use all the resources available.

 

Large Language Models (LLMs), such as ChatGPT and Claude, can help you program, so this is great. But make sure you know what the programming result is supposed to be. Do not blindly trust ChatGPT / Claude. Code from ChatGPT / Clause may not lead to an error (i.e., and exception thrown in Matlab), but may still not provide the correct results. It is your job to know. Claude may currently be better than ChatGPT for programming.

Contact
Information

Dr. Björn Herrmann
Rotman Research Institute at Baycrest
3560 Bathurst St, North York
M6A 2E1, ON, Canada

+1 416 785 2500 ext. 2614

  • LinkedIn
  • X
  • Bluesky_Logo_white
  • Youtube

©2025 by Auditory Aging

bottom of page