How to use Length() In MATLAB
The length() function is used to return the length of the specified array.
Syntax: length(X)
Example:
Matlab
% MATLAB code for detection of duplicate % values of the array using length() % Initializing an array A A = [1 2 3 2 4 3 5 5] % Calling the unique() function over % the above array A to return the % unique values B = unique(A) % Using length() function to return % the size of the above arrays if length(A)==length(B) fprintf( 'Each elements are unique.' ) else fprintf( 'Elements are repeated.' ) end |
Output:
A = 1 2 3 2 4 3 5 5 B = 1 2 3 4 5 Elements are repeated.
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:
Contact Us