Saving for loop output in an array
이전 댓글 표시
I wrote a code in which I predefine the variable "a" and then set up a for loop of 5 iterations where the variable "a" goes through some basic operations. However, the for loop output only saves the fifth iteration of "a." How do I save all 5 iterations in a 1x5 array?
The code is as follows:
a = 10;
k = 0.5;
n = 2;
for m = 1:5
a = a + (a*k) + n;
end
채택된 답변
추가 답변 (1개)
Vivek Selvam
2013년 10월 17일
Terry, this implementation has a different final value.
a(m+1) = a(m) + a(m)*k + n;
Do you want the same final value?
카테고리
도움말 센터 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!