Iterate (repeat) a for-loop n times.
조회 수: 3 (최근 30일)
이전 댓글 표시
Hello.
I am trying to repeat the for-loop n times. The point is that I want to take the values computed in the first iteration of the loop and then use those values in the second iteration of the same loop and so on. Does anybody can help me with that?
Here is my code:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/206607/image.png)
댓글 수: 0
채택된 답변
Star Strider
2019년 3월 3일
You posted an image of your code, not the code we can copy and run.
I would do something like this:
x = 0 : 0.01 : 5;
. . .
for kk = 1:numel(x)
. . .
end
Remember to subscript the values you want to save within the loop, for example:
y2(kk) = y1+h*k;
then plot after the loop (if you want to plot variables you computed in the loop).
댓글 수: 2
Star Strider
2019년 3월 3일
편집: Star Strider
2019년 3월 3일
As always, my pleasure.
The numel function returns the number of elements in an array. For a vector, this is the same as length.
Also, I very much like your avatar (for obvious reasons)!
EDIT — Corrected typographical error.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Eigenvalue Problems에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!