Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

unique

Class: dataset

Unique observations in dataset array

The dataset data type might be removed in a future release. To work with heterogeneous data, use the MATLAB® table data type instead. See MATLAB table documentation for more information.

Syntax

C = unique(A)
[C,ia,ic] = unique(A)
C = unique(A,vars)
[C,ia,ic] = unique(A,vars)
[...] = unique(A,vars,occurrence)
[...] = unique(...,'R2012a')
[...] = unique(...,'legacy')
[...] = unique(A,vars,setOrder)

Description

    Note:   The behavior of dataset.unique is consistent with the MATLAB function unique. For a demonstration of using the 'legacy' flag to preserve the behavior from R2012b and prior in your existing code, see the documentation for unique.

C = unique(A) returns a copy of the dataset A that contains only the sorted unique observations. A must contain only variables whose class has a unique method, including:

  • numeric

  • character

  • logical

  • categorical

  • cell arrays of character vectors

For a variable with multiple columns, its class's unique method must support the 'rows' flag.

[C,ia,ic] = unique(A) also returns index vectors ia and ic such that C = A(ia,:) and A = C(ic,:).

C = unique(A,vars) returns a dataset that contains only one observation for each unique combination of values for the variables in A specified in vars. vars is a positive integer, a vector of positive integers, a variable name, a cell array containing one or more variable names, or a logical vector. C includes all variables from A. The values in C for the variables not specified in vars are taken from the last occurrence among observations in A with each unique combination of values for the variables specified in vars.

[C,ia,ic] = unique(A,vars) also returns index vectors ia and ic such that C = A(ia,:) and A(:,vars) = C(ic,vars).

[...] = unique(A,vars,occurrence) specifies which index is returned in ia in the case of repeated observations in A. The default value is occurrence='last', which returns the index of the last occurrence of each repeated observation in A. occurrence='first' returns the index of the first occurrence of each repeated observation in A. The values in C for variables not specified in vars are taken from the observations A(ia,:). Specify vars as [] to use the default value of all variables.

[...] = unique(...,'R2012a') adopts the future behavior of unique. You can specify the flag as the final argument with any previous syntax that accepts A, vars, or occurrence.

[...] = unique(...,'legacy') preserves the current behavior of unique. You can specify the flag as the final argument with any previous syntax that accepts A, vars, or occurrence.

[...] = unique(A,vars,setOrder) returns the observations of C in a specific order. setOrder='sorted' returns the values of C in sorted order. setOrder='stable' returns the values of C in the same order as A. If there are repeated observations in A, then ia returns the index of the first occurrence of each repeated observation. Specify vars as [] to use the default value of all variables.

See Also

| |

Was this topic helpful?