フィルターのクリア

While loop for array. I want the loop stop when all element of "a" equal "b" but for this loop it will stop when only one element of a equal b. How could I fix it?

2 ビュー (過去 30 日間)
I'd like to use while loop for array.
For example, I have the first array(a) ,10x10x10, and the second array(b),10x10x10 and this following is my condition:
while a ~= b .... a statement.....
end
I want this stop when all element of "a" equal "b" but for this loop it will stop when only one element of a equal b. How could I fix this statement?
Thank you very much

採用された回答

the cyclist
the cyclist 2012 年 12 月 2 日
編集済み: the cyclist 2012 年 12 月 2 日
while not(isequal(a,b))
  2 件のコメント
Nopparat
Nopparat 2012 年 12 月 2 日
It works very well. Thanks a lot!
Marko
Marko 2019 年 11 月 27 日
And how would ich work is it should be equal within a tolerance? Here it is not even doing the while loop bcecause the conditon is true for the last two elements of the arrays.
A = [5,2,1,0,0];
B = [4,1,0,0,0];
error = 0.1;
for i = 1:5
i = i+1
while not (A-B < error))
disp('Increase B')
B = B + 0.01;
end
end

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by