Create a matrix using the following code:
A = [1, 5, 2; 3, 6, 4];
A = 1 5 2 3 6 4
MATLAB stores every matrix, independently of its shape, as a column vector. This vector results from the concatenation of each column in the matrix, from left to right. If a matrix has more than two dimensions, each plane is processed consecutively.
A is stored in memory as the sequence:
1, 3, 5, 6, 2, 4
The order of appearance of each element in the sequence is known as its linear index, counting from 1 (Fig. 1). The concept of linear index is critical to understand linear indexing.
I recommend the following books to learn more on matrix indexing and manipulation in MATLAB:
This book was the winner of a 2017 Textbook Excellence Award. Linear indexing, and other indexing methods, are explained clearly in the second chapter.
MATLAB for Engineers (5th Edition)
This excellent book is especially oriented to engineers and scientists who want to learn MATLAB programming. The fourth chapter is completely dedicated to matrix manipulation.
I also recommend the other tutorials in this series.
- Subscript Indexing in MATLAB
- How MATLAB Stores Matrices in Memory
- Linear Indexing in MATLAB
- How to Convert Linear Indices to Subscripts and Viceversa in MATLAB
- MATLAB end Keyword in Matrix Indexing Expressions
- Logical Indexing in MATLAB
- A Deeper Look on Logical Indexing in MATLAB
- MATLAB Colon Operator in Matrix Indexing Expressions
I hope you have understood how MATLAB stores matrices in memory. The source code developed in this tutorial is available at this page.