how to remove duplicate data in an array in matlab

To remove duplicate values from an array in Matlab, you can use the unique function.

Here's an example:

main.m
myArray = [1, 2, 2, 3, 4, 4, 5];
uniqueArray = unique(myArray);
disp(uniqueArray);
83 chars
4 lines

The output of this code will be:

main.m
1     2     3     4     5
26 chars
2 lines

As you can see, the unique function has removed all duplicates from the array.

You can also use the optional output arguments of the unique function to get the index of each unique value in the original array, or vice versa. For more information on how to use the unique function, please refer to the Matlab documentation.

related categories

gistlibby LogSnag