while-loop condition - arrays equal within a tolerance

10 ビュー (過去 30 日間)
Marko
Marko 2019 年 11 月 27 日
コメント済み: Marko 2019 年 11 月 27 日
Hi guys!
I simplified the problem according to my issue. I basicly want to iterate arrays within a while function. But as soon as one element of the array is true, the while loop is not executed anymore. I want that the while looping is iterating until all elements of the arrays are euqal within a tolerance.
A = [5,2,1,0,0];
B = [4,1,0,0,0];
for i = 1:5
i = i+1
while not(A-B < 0.1*ones(5,1)) & ...
disp('Increase B')
B = B + 0.01;
end
end

採用された回答

Nicolas B.
Nicolas B. 2019 年 11 月 27 日
for you case, I understand that you want the maximum absolute difference being below a limit?
In that case, the "stay in" condition is:
while max(abs(A-B), [], 'all') > you_limit
...
end
the option on the max function is to ensure that you return 1 maximum whatever size have A and B.
  1 件のコメント
Marko
Marko 2019 年 11 月 27 日
This is it! Thank you!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by