MATLAB: Undo-sort does not work for large arrays

sort

Hi,
I am trying to undo a sort in this way:
>> a = [1,2,5,4,3];
>> [b,I] = sort(a);
>> isequal(b(I),a)
ans =
1
But when I try with a larger data set it doesn't work.
>> [ue_seq_sorted, I] = sort(ue_seq);
>> isequal(ue_seq_sorted(I),ue_seq)
ans =
0
>> whos
Name Size Bytes Class Attributes
I 1x98635 789080 double
ue_seq 1x98635 789080 double
ue_seq_sorted 1x98635 789080 double
The data has much larger integers – for example:
Columns 98633 through 98635
135673517 135674897 135676277
Is there another way to sort/undo the sort here?
Thank you!
Kind regards, Martin

Best Answer

The shown method does not even work for small arrays. For your examples the matching result is just an exception.
The 2nd output of sort is not the inverse sorting index.
Please try this (I do not have access to Matlab currently):
[ue_seq_sorted, I] = sort(ue_seq);
index(I) = 1:length(ue_seq);
Related Question