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

2 views (last 30 days)
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 Comments
Torsten
Torsten on 12 Oct 2022
uint64 as a MATLAB data type is not sufficient for your purpose ?
Noor Fatima
Noor Fatima on 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.

Sign in to comment.

Accepted Answer

David Hill
David Hill on 12 Oct 2022
import java.math.*
s=BigInteger('0');
for k=1:length(Data)
s=s.add(Data(k));
end
  2 Comments
Noor Fatima
Noor Fatima on 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

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!