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?

 채택된 답변

per isakson
per isakson 2014년 2월 6일

2 개 추천

댓글 수: 1

Chad Greene
Chad Greene 2014년 2월 6일
Brilliant! Exactly the solution I was hoping for. Thank you!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품

태그

질문:

2014년 2월 6일

댓글:

2014년 2월 6일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by