I need to sort an array but the contents are BigIntegers. When I try use the "sort(A)" function I get the following error:
Error using sort
Unknown command option.
Is it because the array is type BigInteger[] ? And if that's the case, how can I sort it?

 採用された回答

Jan
Jan 2022 年 4 月 29 日

0 投票

How dod you create the array? Please post a short example. I seems that you are talking about a Java class, not a Matlab array. Then use a Java method for sorting...
FEX: HPF might be useful. It has implemented an merge sort.

4 件のコメント

Michelle Lear
Michelle Lear 2022 年 4 月 29 日
I have a for loop that uses a formula to generate the numbers. They were too late to be normal integers so I had to use java.math.* to use BigIntegers within matlab.
z_n = @(n) x_n(n).subtract(y_n(n)).mod(m1);
for i=1:1000
Z(i) = z_n(i);
end
Jan
Jan 2022 年 4 月 29 日
Your code example does not contain any "java.math.BigInter". What is y_n and m1?
Please post a minimal working example, to reduce the need to guess, what you are doing.
With bold guessing:
a = java.util.ArrayList;
for k = 1:5
v = randi([0, 2^16]);
a.add(java.math.BigInteger(typecast(v, 'uint8')));
end
a
a = [542892608, 9623872, 12368960, 2154949440, 3235961408]
java.util.Collections.sort(a)
a
a = [9623872, 12368960, 542892608, 2154949440, 3235961408]
Michelle Lear
Michelle Lear 2022 年 4 月 30 日
I have tried what you wrote in your comment and I get the following :
No method
'java.util.Collections.sort' with
matching signature found.
I imported java.util.* but that doesn't change the outcome.
Jan
Jan 2022 年 5 月 2 日
@Michelle Lear: The link does not uniquely explain, how you have defined your array of BigIntegers. It would be helpful if you post your code instead of letting me guess the details.
I've showed you the code to inster the BigIntegers in a java.util.ArrayList, and this is a valid input for java.util.Collections.sort. If you use the suggested method, you will not get this error message.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeShifting and Sorting Matrices についてさらに検索

製品

リリース

R2021b

質問済み:

2022 年 4 月 29 日

コメント済み:

Jan
2022 年 5 月 2 日

Community Treasure Hunt

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

Start Hunting!

Translated by