MATLAB Fundamentals

An entry-level course on MATLAB - the language of technical computing.
Course info
Rating
(160)
Level
Intermediate
Updated
Apr 4, 2013
Duration
2h 49m
Table of contents
Description
Course info
Rating
(160)
Level
Intermediate
Updated
Apr 4, 2013
Duration
2h 49m
Description

This introductory course on MATLAB shows how to get started with using MATLAB as a language and platform. It covers the basics of MATLAB syntax, explains computational mechanisms including work with arrays and matrices, shows means of data visualization and demonstrates the use of object-oriented principles.

About the author
About the author

Dmitri is a developer, speaker, podcaster, technical evangelist and wannabe quant.

More from the author
ReSharper Fundamentals
Intermediate
2h 54m
Apr 28, 2017
More courses by Dmitri Nesteruk
Section Introduction Transcripts
Section Introduction Transcripts

Introducing MATLAB
Hi. This is Dmitri Nesteruk from Pluralsight. I'd like to welcome you to this course on MATLAB fundamentals. In the first module of this course, I'd like to give an overview of MATLAB as a product. We're going to discuss what MATLAB is, how it's structured, and what are the different ways of actually running MATLAB. Before we get to that, though, let's take a look at the structure of this course. We're starting with this overview module in which we're basically just going to discuss MATLAB as a product. We'll then jump into MATLAB itself, and the first thing we're going to discuss is MATLAB's user interface. We'll then proceed to look at language itself, starting with an introduction to the data types that MATLAB supports, and the ways in which you can manipulate them. We'll move on to basic syntax where you'll see how to perform simple numeric calculations, then we'll discuss arrays and matrices, which happen to be the fundamental building blocks of just about everything you do in MATLAB. We'll then lead the discussion on ways of organizing your work in MATLAB in terms of files, and we'll also take a look at the way you can actually publish MATLAB scripts as readable documents. After that, we'll discuss data visualization; the ways that you can represent data graphically. And we'll finish it all off with a discussion of object-oriented programming, which MATLAB also happens to support.

User Interface
In this module, we'll take a look at MATLAB's user interface. Even though MATLAB is primarily a text-driven product and can be used as a simple text console, the UI does help in many tasks and you shouldn't ignore it. While discussing the various UI elements, we'll also discuss the MATLAB concepts that those UI elements relate to. The core UI of MATLAB is fairly simple, so we'll cover most of it fairly quickly. We'll begin by looking at the various windows that I use to enter commands and keep track of your command history, the values of the current variables, and so on. We'll then talk about window layouts; these are predefined arrangements of windows that you can use to quickly switch from one arrangement to another. And I'll be using window layouts a lot throughout this course. We'll then talk about shortcuts and the locations where they can be placed. Afterwards, I'll show you the brand new Ribbon Interface. We'll go through most of the commands that appear on the Ribbon by default and we'll postpone discussion of any extra Ribbon tabs until our discussion of the features that actually cause them to appear. And finally, I'll talk a little bit about MATLAB's Help and documentation system, which is very elaborate and multifaceted. I'll also talk briefly about the online communities for MATLAB, and the ways of getting help if you run into any trouble.

Data Types
In this module, let's start by looking at the way you actually work with data. And we'll begin by discussing the different data types that MATLAB uses for computation. By data types, we typically mean numeric types with different levels of precision, but also data types for storing text, as well as the more complicated data types. We'll begin by looking at the numeric types that MATLAB supports, and we'll also discuss some of the predefined constants that are available to use as we're working with numeric data. We'll then discuss the specifics of the way that numeric data can be output to the console. We'll then move on to strings, and those aren't as important as numbers, but they're still used in many places within MATLAB. And we'll then take a look at structures, and structures are a great way to effortlessly group data together. We'll then move to the more obscure concept of cell arrays, and we'll finish it all off with a discussion of function handles. One thing I'd like to point out here is that the in-depth discussion of arrays and matrices is postponed, because I'm going to dedicate a whole module just to them. However, I will mention arrays in this module briefly.

Basic Syntax
The purpose of this module is to give you an idea of the basic syntax of MATLAB; and we've already seen some of the MATLAB components in the previous modules, but the goal of this module is to get you comfortable with the different kind of things that MATLAB can do. Pretty much all the work you do in MATLAB will involve the use of variables, so we'll begin by looking at the ways that variables can be defined and manipulated. Just like any other programming language, MATLAB has different operators for doing different things, and we'll take a look at the most important ones. Don't worry, there aren't too many of those. Next we'll talk about flow control, so things like if and switch statements, for loops, that sort of thing. And we'll finish it all off with a discussion of exception handling.

Arrays and Matrices
This module is probably the most important module in the course, because it explains an essential feature of MATLAB: arrays, and the ways that you can work with them. Arrays are a big topic so we've got a lot of ground to cover here. We'll begin by discussing array initializations. And there are lots of ways of actually creating arrays, and we'll cover all the popular ones. We'll then move on to a discussion of how one can access different parts of an array. We'll then discuss the idea of sorting arrays and changing their shape. We'll then talk specifically about two very common operations transposition and inversion. We'll then take a look at why MATLAB has a whole special set of dot prefixed operators specifically for array manipulation. We're then going to talk about yet another array specific operator: the backslash operator, as well as the line solve command; and both of these are used to solve linear systems of equations. And finally, we'll talk about working with arrays that have more than two dimensions. Before we get started I'd like to explain the terminology a little bit. So in MATLAB, as I mentioned already, every variable is an array. So even if you have something that looks like a single scalar value, say x equals 5, it's still considered a 1x1 array, and it can be dynamically expanded on demand. We'll generally use the terms array and matrix interchangeably, though I recommend sticking to arrays, as this makes more sense in a MATLAB setting. There is another term that people often use called vector, and we'll use that term to mean a one dimensional array, so something that is either taking up just one row, so a row vector, or just taking up just one column, a column vector. And with the terminology out of the way, let's finally get started.

Working with Scripts
There are two ways of performing computations in MATLAB, one way is to simply type things into the command window and watch them execute, and the other is to use script, which is simply text files that can be executed by MATLAB, either in whole or in part. We'll begin by taking a look at script templates and specifically we'll make use of a function template to define a simple function and watch how it can be executed. We'll then discuss how functions can be made accessible to any other location in MATLAB via the use of path settings. We'll then look at MATLAB search capabilities, as well as a very simplistic file comparison tool it provides. After that, we need to discuss the idea of sections. Sections are useful for splitting up large script files into manageable chunks that can be executed separately. We'll then discuss the idea of using breakpoints to debug scripts, as well as using the MATLAB profiler to optimize script execution speeds. We'll then talk about publishing your scripts as readable documents. And since you need some way of representing mathematical formulae, I'm going to discuss the LaTeX typesetting language, which MATLAB also supports.

Data Visualization
MATLAB is all about computation, but sometimes you just want to see the data visually, and in this case you can create a plot of the data using the many mechanisms that MATLAB gives you. The simplest way to plot some data is to do it via the user interface. So that's what we're going to begin with. We'll then move to doing plots entirely from the console and discuss the ways that one can plot data. I'll also discuss the idea of plotting symbolic functions, even though this is part of the symbolic toolbox. We'll then discuss figure windows and the ways that one can have several sets of data plotted on a single graph. We'll then take a look at adding various text annotations, such as labels to the plots. As well as ways of combining multiple plots in a single window. I'll then show some of MATLAB's functionality for editing the plot in the figure window. And to finish it all off, I'll discuss one problem with MATLAB, which involves the rendering of origin axis.

Object Oriented Programming
So far all that we have seen in MATLAB is a fairly procedural style of programming where statements get executed in the order they are defined. To add structure and support larger more complicated scripts, MATLAB supports the notion of object-oriented programming. And this mechanism allows for clear organization of properties and behavioral aspects of different concepts. I must once again warn the programmers in the audience that the content of this module will be somewhat trivial if you're already used to object-oriented programming. This module discusses the foundations of object-oriented programming in MATLAB. And central to this is the use of classes. So we'll take a look at the way they are defined. We'll then take a look at ways of actually storing data in classes using properties. Properties are in many ways similar to fields that are part of structures that we've seen already, but they're a bit more powerful. We'll then talk about adding actual behaviors to the class by defining methods. We'll then discuss events, which are used by classes to notify all the classes that something has changed. We'll then talk about another central idea of object-oriented programming. The concept of inheritance, which lets classes basically inherit or acquire properties and methods from other classes. We'll then take a look at enumerations, which are simply a special type of class for representing a discrete set of values.