How to use sortrows command in java.math.BigInteger?

Let A be BigInteger array (mx2)
I want to apply sortrows on A,
but it is not compatible with it .
import java.math.BigInteger.*;
e.g
A = [2 1; 2 2; 3 5; 3 6; 8 6; 8 4];
B = sortrows(A)
But when I used sortrows on BigInteger data, then the following error occur
Error using sort
Unknown command option.
Error in sortrows>sortBackToFront (line 119)
[~,ind] = sort(A(I,abs(ck)),directions{(ck < 0) + 1},opts{:});
Error in sortrows (line 73)
I = sortBackToFront(A, col, nanflag, compareflag);

Réponses (1)

import java.math.*
%load sample BigInteger Array (100x2)
for k=1:100
J(k,:)=[BigInteger(repmat(num2str(randi(1e14,1)),1,3)),BigInteger(repmat(num2str(randi(1e14,1)),1,3))];
end
%have to do sort manually, any sort algorithm will work but need to use
%compareTo() for BigIntegers
c=0;
while c~=size(J,1)-1
c=0;
for k=1:size(J,1)-1
if J(k,1).compareTo(J(k+1,1))==0&&J(k,2).compareTo(J(k+1,2))==1
temp=J(k+1);
J(k+1)=J(k);
J(k)=temp;
elseif J(k,1).compareTo(J(k+1,1))<1
c=c+1;
else
temp=J(k+1);
J(k+1)=J(k);
J(k)=temp;
end
end
end

Catégories

En savoir plus sur Matrices and Arrays dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by