Comparing updated array from two consecutive iterations

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 日

2 投票

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 日

1 投票

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

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

質問済み:

2017 年 4 月 16 日

編集済み:

2017 年 4 月 18 日

Community Treasure Hunt

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

Start Hunting!

Translated by