How to store the output of the following for loop ?
import java.math.*;
a = BigInteger('12345678');
c = Biginteger('67436255757');
n = BigInteger('10');
for i=1:double(n)
a = my_function(a,c );
end
where
function [a] = my_function(b,c )
import java.math.*;
a = b.add(c) ;
end
Thanking in anticipation.

답변 (2개)

Arif Hoq
Arif Hoq 2022년 3월 5일

0 개 추천

import java.math.*;
a = BigInteger('12345678');
c = BigInteger('67436255757');
n = BigInteger('10');
for i=1:double(n)
y = my_function(a,c );
end
output=sprintf('%10.0f',y)

댓글 수: 2

Ammy
Ammy 2022년 3월 5일
편집: Ammy 2022년 3월 5일
@Arif Hoq Thank you, but the above is not storing all the output, also I can't use y = my_function(a,c );because my function is like a recursive function every new output depends on the previous
Ammy
Ammy 2022년 3월 5일
@Arif Hoq But it stores only the last output
I want to store output in each iteration like if n=10 there should be 10 ouputs

댓글을 달려면 로그인하십시오.

Image Analyst
Image Analyst 2022년 3월 6일

0 개 추천

for k = 1 : round(n)
a(k) = my_function(a, c); % Save the output for every iteration of the loop.
end

댓글 수: 2

Ammy
Ammy 2022년 3월 7일
@Image Analyst Thank you very much, but I'm getting the following error
Error using round
First argument must be a numeric, logical, or char array.
Image Analyst
Image Analyst 2022년 3월 12일
편집: Image Analyst 2022년 3월 12일
What data class is n?
whos n
If n is already an integer, you don't need to round it
for k = 1 : n
a(k) = my_function(a, c); % Save the output for every iteration of the loop.
end

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

질문:

2022년 3월 5일

편집:

2022년 3월 12일

Community Treasure Hunt

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

Start Hunting!

Translated by