Does the "unique" function work with 64 bit integers?

I was trying to sort a set of 64 bit integers using the "unique" function. This function seems to convert them to a 64 bit integer before sorting, though.
Example:
x=uint64(2^63)+uint64(0:1024)';
y=unique(x);
The output, y, is a single number, 9223372036854775808, rather than a column of 1025 integers, since the last 11 bits are rounded off.
The "sort" sorts the data properly, but does not remove duplicates. Are there any other solutions? I am using Matlab R2012a.

 채택된 답변

James Tursa
James Tursa 2016년 8월 24일
Maybe use something similar to this as a workaround:
y = x(logical([1;diff(sort(x))]));

댓글 수: 1

Ken
Ken 2016년 8월 24일
Yes. That works. The hard part was figuring out why my output did not match my input. I see in the UNIQUE function code where it changes the input to double precision. There is a comment in the code that "UNIQUE calls DIFF, which requires double input." This has not been true since R2010b, when the DIFF function began to work with integers. Thanks.

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기

태그

질문:

Ken
2016년 8월 24일

댓글:

Ken
2016년 8월 24일

Community Treasure Hunt

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

Start Hunting!

Translated by