function of two variables
조회 수: 1 (최근 30일)
이전 댓글 표시
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??
댓글 수: 0
답변 (1개)
madhan ravi
2020년 9월 18일
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
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.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!