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?

답변 (1개)

Walter Roberson
Walter Roberson 2015년 10월 17일

0 개 추천

unique([x,y],'rows')

댓글 수: 1

regina
regina 2015년 10월 18일
편집: regina 2015년 10월 18일
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!

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

제품

질문:

2015년 10월 17일

편집:

2015년 10월 18일

Community Treasure Hunt

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

Start Hunting!

Translated by