How to resolve problem in for loop?
1 view (last 30 days)
Show older comments
a=java.math.BigInteger(100)
for i=1:a
a*a;
end
Undefined function '_colonobj' for input arguments of type 'java.math.BigInteger'.
Any help in this regard is much appreciated. Thanks
0 Comments
Answers (1)
John D'Errico
on 11 Dec 2021
Edited: John D'Errico
on 11 Dec 2021
Is "a" a number, in the form MATLAB will expect it? NO! a is a BigInteger number. You cannot use the colon operator on a.
a=java.math.BigInteger(100)
whos a
So you could have used a loop like this:
for i = 1:double(a)
As far as the actual loop goes, What do you think this
a*a;
does? NOTHING. Well, it does something. It throws an error. Because again, multiplcation is NOT supported in MATLAB between java.math.BigInteger objects. And even if it was supported, it would do nothing useful in MATLAB, just dumping the result into the bit bucket.
Anyway, if you want to multiply BigInteger numbers, the Java toolbox provides such a tool. Admittedly, it is a bit of a pain in the neck. This is why I put my own wrapper around those tools for use in MATLAB.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!