use of the unique function

i have a problem
I need to find rows that are not unique in a table column. I really have no idea how to start.
the column could be the following:
apartments
[a1; a2; a3; a1; a4; a5]
I need to find the rows that are non unique and write an error message
hope you can help

 Accepted Answer

Try this:
apartments = ['a1';
'a2';
'a3';
'a1';
'a4';
'a5'];
[aptu,~,ix] = unique(apartments, 'rows','stable');
tally = accumarray(ix, 1);
NotUnique = aptu(tally>1,:)
NotUnique =
'a1'
You specified a two-column character array, and this will work with the data you provided.
You may need to experiment with your actual data to get the result you want. See the documentation for the unique (link) function.

2 Comments

Thanks a lot for the answer, it seems like it works!
As always, my pleasure!

Sign in to comment.

More Answers (0)

Tags

Asked:

AFT
on 6 May 2018

Edited:

AFT
on 7 May 2018

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!