i had a function with two variables f(x1,x2)
in loop for k times
how can i calculate the value of the function in each iteration??

답변 (1개)

madhan ravi
madhan ravi 2020년 9월 18일

0 개 추천

C = cell(numel(x1));
for k = 1:numel(x1)
C{k} = f(x1(k), x2(k)); % of f() is vectorised you won’t need a loop
end
celldisp(C)

댓글 수: 2

saja mk
saja mk 2020년 9월 18일
thank you alot for your reply , but can you please explain what you meant by
C = cell(numel(x1)); ??
madhan ravi
madhan ravi 2020년 9월 18일
I was preallocating variable C , which makes the code more optimised . You could look up preallocation and explore why it’s important.

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

카테고리

도움말 센터File Exchange에서 Performance and Memory에 대해 자세히 알아보기

태그

질문:

2020년 9월 18일

댓글:

2020년 9월 18일

Community Treasure Hunt

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

Start Hunting!

Translated by