Updated March 13, 2023

## Introduction to NUMEL Matlab

The NUMEL function is used to count the number of array elements. It is also used to count the number of elements in the database. The NUMEL performed in MatLab is employed to search out the number of elements in an array, The result of numel is the same as the prod(size(z)). We can count any number of elements from the database, there are no such criteria or requirements for database format. Any type of database is accessible to numel functions such as arrays, vectors, or multidimensional matrices.

**Syntax:**

The syntax of numel is given as follow: –

`h = numel ( z )`

### How to Do NUMEL Matlab?

h = numel ( z ) returns the number of elements , z , in array h , equivalent to prod ( size ( z ) ) . In this format, h represents output variable name and z is the input variable name by using z we can pass any random database values to the function. And accordingly, it will create results in the form of several elements present at the input side.

### Examples of NUMEL Matlab

Here are the following examples mentioned below.

#### Example #1

Let us consider one example, firstly Matrix, and then compute it using MatLab.

In this example, we have to create a 6 – by – 6 – by-2 matrix. To create Matrix have use numel function along with the magic Matlab function.

**Code:**

`clc;`

clear all;

h = magic( 5 );

h(:,:,2)=h'

n = numel( h )

**Output:**

e = magic ( n ) returns an n-by-n matrix constructed from the integers 1 through n^ 2 with equal row and column sums. In the above example magic function is used to create a 6 – by – 6 – by – 2 matrices. As per that matrix h ( : , : , 1 ) and matrix h ( : , : , 2 ) is created . and then to count the number of elements in the matrix we used numel function. And the result is** t**he total count of elements is 50.

#### Example #2

Now let us consider the second example, we can create a cell array of character vectors, and then we can compute it to see the result in Matlab. Here we use array a having n number of characters

Then to find how many elements are in the array we use numel Matlab function.

**Code:**

`clc;`

clear all;

d = {'Bing Cherry.',' Crab apples','orange.','Evergreen_Huckleberry'};

n = numel( d )

**Output:**

In the above example, a cell array of character vector of fruits is given. All fruits are kept in set ‘d ’. To find the total numbers of fruits inset ‘ d ’ use Matlab function numel.

The total count of fruits inset ‘ d; is 4.

#### Example #3

Let us consider another example; in this example, we can create one table of student information. These table fields are like student name, roll number, weight, height, and year. We can store the number of student information and as well we can also take this student information by the user instead of giving it directly in Matlab. After generating the table we can now use the numel Matlab function to see the number of elements in that table. And the result is stored in the variable ‘ z ’.

**Code:**

`clc;`

Name = {'Ram'; 'Raju'; 'Seeta'; 'Geeta'; 'Rani'};

Roll_no = [ 40; 30; 28; 48; 19 ];

Weight = [ 40; 55; 65; 85; 50 ];

Height = [ 170; 169; 140; 138; 175 ];

Year = [ 2; 4; 1; 2; 3 ];

D = table( Roll_no , Weight , Height, Year , ' RowNames ' , Name )

Z = numel( D )

**Output:**

### Conclusion

In this article, we have seen how to use numel function use in Matlab. It can be applied to count the number of array elements, to count the number of elements in the database with other major terminologies in programming. By using numel function we can pass multiple parameters as well as function names to the code.

### Recommended Articles

This is a guide to NUMEL Matlab. Here we discuss How to Do NUMEL Matlab and Examples along with the codes and outputs. You may also have a look at the following articles to learn more –