any way to avoid this loop?
Afficher commentaires plus anciens
I'm familiar with the benefits of vectorizing code, but is there a way to avoid a loop when the solution to each value in an array depends on the value before it? A minimal working example of a loop I'd like to avoid:
x = ones(1,1000);
for n = 2:length(x)
x(n) = 2*x(n-1) - 10;
end
Ideas for a generalized solution? Or perhaps there's simply a faster technique I should learn about?
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!