Table of Contents
Overview
MATLAB is both a programming language and an interactive environment. In this part of the course you focus on the language itself: how MATLAB code looks, how it behaves when you type commands, and what kind of data it works with. This chapter gives you a big-picture view of the MATLAB language so that the more detailed chapters that follow will make sense.
You will see how MATLAB expressions are evaluated, how variables store data, what common data types you will meet early on, how vectors and matrices fit into everything, what elementwise operations are, and how MATLAB’s many built-in constants and functions fit into the usual workflow. Later chapters in this section will treat each of these topics in more detail. Here you connect them conceptually and learn what to expect when you start writing MATLAB code.
MATLAB as a Matrix-Oriented Language
The name MATLAB comes from “matrix laboratory”. This is reflected in the core of the language. The basic things that MATLAB works with are arrays. Scalars, vectors, and matrices are all stored as arrays internally. When you type a simple arithmetic expression, MATLAB usually interprets it in terms of array or matrix operations.
For example, when you write A * B, MATLAB assumes you want matrix multiplication with the standard rules from linear algebra. At the same time, MATLAB lets you apply operations to each individual element using special syntax, which you meet later as elementwise operations.
Because arrays are central, many functions in MATLAB are written to work on a whole vector or matrix at once. This is different from languages that focus on looping through individual elements as the default style. As a MATLAB user, you learn to think in terms of whole-array operations. A large part of “speaking MATLAB” is learning to write expressions that work on an entire vector or matrix in a single line.
Expressions and Evaluation
A MATLAB expression is a combination of numbers, variables, operators, and function calls that MATLAB can evaluate to produce a result. You type the expression at the command line or in a script, MATLAB parses it, evaluates it from right kind of operators to left, and either displays the result or stores it in a variable.
The basic arithmetic operators look familiar: + for addition, - for subtraction, * and / for multiplication and division, and ^ for powers. MATLAB also follows a standard order of evaluation, sometimes called operator precedence. Powers are applied before multiplication and division, which are applied before addition and subtraction. Parentheses always take priority, so you can control the evaluation order explicitly. This becomes important as soon as you write longer expressions involving arrays and functions.
In practice, almost every useful expression in MATLAB uses functions. A function call looks like name(input1, input2, ...). For example, sin(x), sqrt(A), or size(B). MATLAB has hundreds of built-in functions, and most of them accept vectors and matrices as inputs. You can combine them with arithmetic operators to form more complex expressions, all evaluated in a predictable order.
Variables as Named Storage
Variables in MATLAB are names that refer to stored values. When you evaluate an expression and assign it to a variable using =, MATLAB creates that variable in the current workspace and remembers its value until you change or clear it. For instance, in an interactive session you can compute a result, assign it to a name, and reuse that name in later expressions.
A variable does not need to be declared in advance. The first time you assign something to a name, MATLAB creates the variable and sets its type based on the value you store. Over time, this same name can refer to different types of data if you assign something new. This makes experimentation easy, but it also means you must pay attention to which values and types your variables currently hold.
There are simple rules about how you can name variables, such as which characters are allowed and how MATLAB distinguishes between upper and lower case. You also want to avoid using names that MATLAB already uses for its functions to prevent confusion. You explore these rules and common patterns in the dedicated chapter on variables and assignment, but for now it is enough to treat variables as labels that you can attach to any computed quantity.
Data Types You Will Meet Early
Every value in MATLAB has a type that determines how MATLAB stores it in memory and how it behaves in operations. The most typical numeric type for beginners is a double precision floating point number, often called just “double”. When you type numbers such as 3, 5.7, or -2e3, MATLAB usually stores them as doubles. This default makes numeric work straightforward, since most math functions expect and return doubles.
Beyond basic floating point numbers you will encounter other numeric types, such as integer types, as well as characters and strings for text. Arrays can be made out of many of these types, so you get vectors of doubles, matrices of integers, arrays of logical values, and more. Type conversion functions let you transform a value from one type to another when necessary.
At this stage you do not need to know every type. The important idea is that types exist, that they can differ, and that MATLAB usually chooses a type automatically when you create a value. Later you see how to check a variable’s type, when you might want to change it, and how conversions behave.
Vectors and Matrices as Fundamental Structures
Although numbers are important, MATLAB becomes truly useful when you move to vectors and matrices. A vector is a one-dimensional array. It can be a row or a column. A matrix is a two-dimensional array defined by its numbers of rows and columns.
In MATLAB, vectors and matrices are the default way to store collections of numbers. When you run calculations, most functions can operate on whole vectors or matrices in one call. For example, you will frequently evaluate functions on every element of a vector, or multiply matrices to combine linear transformations. This is why the basic data structure in MATLAB is the array, with vectors and matrices as the most common shapes.
You will learn concrete ways to create these arrays, including literal notation and functions that generate sequences or special patterns. You also learn how to access individual elements or blocks of elements through indexing and slicing. In this overview it is enough to note that, in MATLAB, working with multiple numbers almost always means working with arrays.
Arrays and Elementwise Thinking
Because almost everything is an array, MATLAB provides two styles of arithmetic with arrays. One style follows the rules of linear algebra, where * and / represent matrix multiplication and matrix division, and ^ represents matrix powers. The other style treats each array element separately. In that style the operator is applied to each element in the input, producing a new array of the same size.
This second style is known as elementwise operations. MATLAB uses a simple visual convention for these operators. Elementwise multiplication, division, and power are written with a dot in front of the operator, like ., ./, and .^. For example, if A and B are arrays of the same size, then A . B multiplies corresponding entries in A and B. On the other hand, A * B tries to perform matrix multiplication and requires compatible dimensions in the linear algebra sense.
Elementwise operations are central to the MATLAB way of writing code. They let you apply formulas to each element of a vector or matrix without writing explicit loops. As you work through the later chapter on basic arithmetic and elementwise operations you will see how this lets you express mathematical ideas in MATLAB in a form that looks close to the original mathematical notation.
Built-In Constants and Functions as Building Blocks
MATLAB includes a large library of functions and a set of predefined constants that you can use immediately. Common mathematical constants such as $\pi$ have built-in names. Statistical values, imaginary units, and special Not-a-Number representations are also available. You do not need to define these yourself, which reduces the chance of typing mistakes in fundamental values.
Functions are the main building blocks that let you perform calculations on your data. There are functions for trigonometry, exponentials, logarithms, linear algebra, statistics, optimization, and much more. Many of these functions are written to be vectorized, meaning they can accept an entire vector or matrix and apply the operation to each element automatically. This is why vectors and matrices combine so naturally with the built-in functions.
As a beginner you concentrate on using these functions rather than writing your own. You pass them variables, combine their outputs in expressions, and gradually learn which functions are suitable for which tasks. Later in the course you learn how to create your own functions, but at this language basics stage you treat built-in functions as your main tools for performing work in MATLAB.
How the Pieces Fit Together
When you write MATLAB code, you combine all of these elements. You start with variables that store arrays, usually doubles. You create vectors and matrices to represent your data and use indexing to access the parts you need. You write expressions that use arithmetic operators and built-in functions to transform that data. You choose between matrix operations and elementwise operations depending on whether you are expressing a linear algebra computation or applying the same formula to each element. Throughout, MATLAB keeps track of types, shapes, and values for you.
Understanding the language at this level prepares you to go into each specific topic in detail. Variables and assignment, data types and conversion, arrays, indexing, arithmetic rules, and the standard library of functions each deserve careful study. The remaining chapters in this section guide you through those ideas step by step, so you can move from simple commands to clear and expressive MATLAB programs.
Key ideas to remember:
MATLAB is built around arrays, with vectors and matrices as the usual way to store numbers.
Expressions combine variables, operators, and functions, and MATLAB follows a defined order of evaluation.
Variables are created by assignment and hold values together with their types.
Elementwise operators such as . and .^ apply arithmetic separately to each array entry, while and ^ express matrix operations.
Built-in constants and functions are your main tools for early work in MATLAB and are designed to work naturally with arrays.