How to write a code for an iteration?
조회 수: 3 (최근 30일)
이전 댓글 표시
Hi there I would like to run an iterative code.
I would like to start with a matrix f0=[a,b,c,d]
Then I would like to compute the following operation
f1=[a+b,c+d,a-b,c-d]
I would like this to be done iteratively and so that the script uses the value before.
that is f100 uses the a,b,c and value from f99.
How would I do this?
댓글 수: 0
채택된 답변
Dennis
2018년 12월 14일
f=zeros(100,4);
f(1,:)=[1 5 10 15];
for i=2:100
f(i,:)=[f(i-1,1)+f(i-1,2),f(i-1,3)+f(i-1,4),f(i-1,1)-f(i-1,2),f(i-1,3)-f(i-1,4)];
end
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!