To remove repeating values from an array in MATLAB, you can use the unique()
function.
Here's an example:
main.m49 chars4 lines
This will output: [1 2 3 4 5 6]
The unique()
function returns a new array with only the unique values of the input array. By default, the function sorts the output array in ascending order. If you want to keep the original order, you can use an additional output argument:
main.m39 chars2 lines
The idx
array contains the indices of the input array that correspond to the unique values in A_unique
.
gistlibby LogSnag