any way to avoid this loop?
1 view (last 30 days)
Show older comments
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?
0 Comments
Accepted Answer
More Answers (0)
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!