unique values inside a matrix
이전 댓글 표시
Hello,
Assuming i have a matrix like this m=
1 30
1 20
1 20
1 20
2 30
2 28
2 28
... ...
i want it to be like this:
1 30
1 20
2 30
2 28
PS: THE MATRIX IS HUGE CONSISTING OF 11000 ROWS AND 9 COLUMNS
unique is not working since it has it's taking a unique value of all, for example if i apply it for the second column it will take 28 for 1 and not for 2
thank you in advance
채택된 답변
추가 답변 (1개)
Guillaume
2019년 9월 21일
I'm not sure what you mean by unique is not working. You haven't explained the reasoning for going from your input to your output, but it does look like you want unique rows:
result = unique(m, 'rows')
With your demo data:
>> m = [
1 30
1 20
1 20
1 20
2 30
2 28
2 28];
>> unique(m, 'rows')
ans =
1 20
1 30
2 28
2 30
>> unique(m, 'rows', 'stable') %with stable to get the same order as your example
ans =
1 30
1 20
2 30
2 28
댓글 수: 5
Michel tawil
2019년 9월 21일
Guillaume
2019년 9월 21일
The simplest way for us to understand what you're talking about is to attach a mat file with your data to your question.
>> unique([20; round(19.8)])
ans =
20
As you can see it's not a problem unique returns just one value. Whatever your data is, it's not exactly how you describe it.
Possibly, it's something like:
>> v = [20; 20+1e-14]
v =
20
20
>> unique(v) %return 2 elements because the 2nd one is not exactly 20.
ans =
20
20
>> ans - 20
ans =
0
1.06581410364015e-14
Michel tawil
2019년 9월 21일
Michel tawil
2019년 9월 21일
Michel tawil
2019년 9월 22일
카테고리
도움말 센터 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!