How to take the sum of all the values in an array ?

3 vues (au cours des 30 derniers jours)
Noor Fatima
Noor Fatima le 12 Oct 2022
Commenté : Noor Fatima le 12 Oct 2022
I have a Data in java. math.BigInteger format.
Data =
java.math.BigInteger[]:
[java.math.BigInteger]
[java.math.BigInteger]
[java.math.BigInteger]
[java.math.BigInteger]
[java.math.BigInteger]
[java.math.BigInteger]
[java.math.BigInteger]
[java.math.BigInteger]
[java.math.BigInteger]
[java.math.BigInteger]
[java.math.BigInteger]
[java.math.BigInteger]
[java.math.BigInteger]
[java.math.BigInteger]
For any two values we can add like this
result = Data(1).add(Data(2))
But how can we add all the values in the large Data?
  2 commentaires
Torsten
Torsten le 12 Oct 2022
uint64 as a MATLAB data type is not sufficient for your purpose ?
Noor Fatima
Noor Fatima le 12 Oct 2022
@Torsten Thank you very much, my data is in java.math.BigInteger, and as I think unit64 is not compatible with that.

Connectez-vous pour commenter.

Réponse acceptée

David Hill
David Hill le 12 Oct 2022
import java.math.*
s=BigInteger('0');
for k=1:length(Data)
s=s.add(Data(k));
end
  2 commentaires
Noor Fatima
Noor Fatima le 12 Oct 2022
Hi David,
Thank you !
Noor Fatima
Noor Fatima le 12 Oct 2022
@David Hill I have also asked the question with the same format.
Please have a look on the following
https://www.mathworks.com/matlabcentral/answers/1823533-how-to-sort-rows?s_tid=srchtitle

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Call Java from MATLAB dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by