COUNTUNIQUE Function

COUNTUNIQUE (x <, method> ) ;

The COUNTUNIQUE function counts the number of unique values in a matrix. The arguments are as follows:

x

specifies an $n\times p$ numerical or character matrix. The COUNTUNIQUE function counts the number of unique values in this matrix.

method

specifies the method used to count the missing values. This argument is optional. The following are valid values:

all

specifies that the function counts all unique values in the matrix. This is the default value. The function returns a $1\times 1$ matrix.

row

specifies that the function counts the unique values in each row. The function returns an $n\times 1$ matrix whose $i$th element is the number of unique values in the $i$th row of x.

col

specifies that the function counts the unique values in each column. The function returns a $1\times p$ matrix whose $j$th element is the number of unique values in the $j$th column of x.

The method argument is not case-sensitive. The first three characters are used to determine the value.

For example, the following statements count unique values for the matrix x:

x={1 2 3, 
   1 1 2, 
   1 1 1, 
   1 0 0};
allUnique = countunique(x);
rowUnique = countunique(x, "ROW");
colUnique = countunique(x, "COL");
print allUnique, rowUnique, colUnique;

Figure 23.73: Counts of Unique Values

allUnique
4

rowUnique
3
2
1
2

colUnique
1 3 4