How to find unique

2 views (last 30 days)
regina
regina on 17 Oct 2015
Edited: regina on 18 Oct 2015
I have two columns of numbers, X and Y, and i need to find each unique combination of numbers, so far i have this code
s=0
for i=1:n;
if length(unique(x(i)))==x(i);
s=s+length(unique(y(i)));
else if length(unique(y(i)))==y(i);
s=s+length(unique(x(i)));
end
end
end
I'm getting closer to my answer, so hopefully it just needs a few small tweaks, but i can't figure out what?

Answers (1)

Walter Roberson
Walter Roberson on 17 Oct 2015
unique([x,y],'rows')
  1 Comment
regina
regina on 18 Oct 2015
Edited: regina on 18 Oct 2015
okay, so i've defined
date=unique([x, y], 'rows');
outside of my for loop, where x and y are previously defined as the two different columns, then my for loop:
x=0
for i=1:ngames;
if 2003==year(i) & numel(date);
x=x+1;
end
end
where ngames=size(tab,1);
year=another column
but this is giving me the number of rows in 2003, but instead i want the number of unique dates in 2003
EDIT:wait actually, on the left hand side in the workspace tab, a table of variables has been created called date 192x2, and when i open this they are the values i want, how do i get it so it prints the answer 192? Thanks
EDIT 2:okay, solved this now by using length(date)
thank you for pointing me in the right direction!

Sign in to comment.

Products

Community Treasure Hunt

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

Start Hunting!