You can use the unique() function in MATLAB to identify the unique values in a dataset. To select one of the duplicated values over the other, you can use the unique() function with the 'last' or 'first' argument, which returns the index of the last or first occurrence of a duplicated value, respectively. Here's an example:
Let's say you have a dataset dates as shown below, and you want to identify the unique values and select the first occurrence of each unique value:
main.m241 chars8 lines
In this example, uniqueDates will be ["2021-05-01", "2021-05-02", "2021-05-03"], and uniqueDatesFirstOccurrence will be ["2021-05-01", "2021-05-02", "2021-05-03"].
If you want to select the last occurrence of each unique value instead, you can pass the argument 'last' to the unique() function:
main.m105 chars3 lines
In this case, uniqueDatesLastOccurrence will be ["2021-05-03", "2021-05-02", "2021-05-01"].
gistlibby LogSnag