To error check unique values of a dataset in MATLAB, you can use the unique
function. The unique
function returns an array with the unique elements in the input array. By comparing the length of the input array with the length of the output array, you can determine whether the input array has any duplicate values.
Here's an example code:
main.m207 chars9 lines
In the example code, the data
array contains duplicate values (5), so the output will be:
main.m36 chars2 lines
If the data
array had contained only unique values, the output would have been:
main.m38 chars2 lines
Note: This method will only detect any duplicate values in your dataset, it doesn't specify which element(s) in the dataset are duplicates.
gistlibby LogSnag