Comparing updated array from two consecutive iterations

조회 수: 4 (최근 30일)
AndrewA
AndrewA 2017년 4월 16일
편집: AndrewA 2017년 4월 18일
Hi, I need to create a while loop for a for loop which iterates until the difference between the array c of the current iteration and the array c of the previous iteration is small. Any suggestions on how I could save the updated array for each iteration and then compare the 2 consecutive iterations?

채택된 답변

Stephen23
Stephen23 2017년 4월 16일
편집: Stephen23 2017년 4월 16일
Like this:
prv = 0; % pick first previous value
for ...
new = ...
...compare prv & new, do whatever
prv = new;
end

추가 답변 (1개)

Roger Stafford
Roger Stafford 2017년 4월 17일
Use a while loop that is sure to make at least two trips through.
old = all NaNs so as to surely fail 1st test
b = false;
while ~b
new = ...
b = old and new difference is sufficiently small
old = new;
end

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by