Create a matrix using the following code:
A = [1, 2, 3; 4, 5, 6];
A = 1 2 3 4 5 6
n = numel(A) stores in
n the number of elements in matrix
% Get the number of elements in matrix A n = numel(A);
n = 6
I recommend the following books to learn more on matrix manipulation in MATLAB.
This book was the winner of a 2017 Textbook Excellence Award. The second chapter is dedicated to matrix manipulation and includes topics like matrix creation and indexing, and how to perform a wide list of operations on matrices.
MATLAB for Engineers (5th Edition)
This excellent book is especially oriented to engineers and scientists who want to learn MATLAB programming. Matrix manipulation is explained in the fourth chapter.
I also recommend the following page in the MATLAB help documentation, and the other tutorials in this series.
- How to Get the Size of a Matrix in MATLAB
- How to Get the Number of Elements in a Matrix in MATLAB
- How to Get the Number of Dimensions of a Matrix in MATLAB
- How to Reshape a Matrix in MATLAB
- How to Delete Items From a Matrix in MATLAB
- How to Transpose a 2D Matrix in MATLAB
- How to Transpose a Multidimensional Matrix in MATLAB
- How to Reverse a 2D Matrix in MATLAB
- How to Reverse a Multidimensional Matrix in MATLAB
I hope you have learned how to get the number of elements in a matrix in MATLAB. The source code developed in this tutorial is available at this page.