How to use numel() In MATLAB
The numel() function is used to return the number of elements present in a specified array.
Syntax: numel(A)
Example:
Matlab
% MATLAB code for detection of duplicate % values of the array using numel() % Initializing an array A = [0 2 4 1 2 3 0 4] % Calling the unique() function % over the above array to return % unique elements [B] = unique(A) % Using setdiff() and numel() functions % together to get the indices of repeated % elements duplicate_indices = setdiff(1:numel(A), B) |
Output:
A = 0 2 4 1 2 3 0 4 B = 0 1 2 3 4 duplicate_indices = 5 6 7 8
How to detect duplicate values and its indices within an array in MATLAB?
In this article, we will discuss how to find duplicate values and their indices within an array in MATLAB. It can be done using unique(), length(), setdiff(), and numel() functions that are illustrated below: