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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!