May i know why i can't write: while(N~=[0 0 0]) in matlab?

1 回表示 (過去 30 日間)
jy tan
jy tan 2011 年 12 月 4 日
N is a 1x3 array

採用された回答

Walter Roberson
Walter Roberson 2011 年 12 月 4 日
while (N~=[0 0 0])
is valid syntax in MATLAB. The comparison would take place, giving a logical vector. When an "if" or "while" is asked to make a decision about a logical vector or array, it considers it to be true if and only if all of the elements of the vector or array are non-zero (true).
It is well-defined behavior, but if you think about it, the loop would stop as soon as one or more of the elements of N became 0.
You may instead wish to use
while any(N~=[0 0 0])
which could be rewritten
while any(N~=0)
  1 件のコメント
Jan
Jan 2011 年 12 月 4 日
which could be rewritten to "while any(N)".

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeBig Data Processing についてさらに検索

タグ

タグが未入力です。

Community Treasure Hunt

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

Start Hunting!

Translated by