function of two variables
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposte (1)
madhan ravi
il 18 Set 2020
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 Commenti
madhan ravi
il 18 Set 2020
I was preallocating variable C , which makes the code more optimised . You could look up preallocation and explore why it’s important.
Vedere anche
Categorie
Scopri di più su Performance and Memory in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!