while statements - imposing two conditions

1 回表示 (過去 30 日間)
Bran
Bran 2013 年 7 月 1 日
Hi there I am trying to impose a while loop with two conditions;
while (L2normpercentold>=tol)&&(any(Diffpart1>0.0001)) However I get the following error;
??? Operands to the and && operators must be convertible to logical scalar values.
Error in ==> reconstructionofimagetester6 at 48 while (L2normpercentold>=tol)&&(any(Diffpart1>0.0001))
Any way around this

回答 (2 件)

Jonathan Sullivan
Jonathan Sullivan 2013 年 7 月 1 日
Sounds like either L2normpercentold or Diffpart1 are not scalars. How you get around this depends on what type of behavior you want. Do you want all elements to satisfy the condition? Or would you like be ok with only one of the elements satisfying the condition?
The functions all and any would come in handy here.

Evan
Evan 2013 年 7 月 1 日
編集済み: Evan 2013 年 7 月 1 日
Is Lnormpercentold a scalar or a vector? You can receive this error when attempting to use the && operator to compare logical vectors. So, depending on what you want, you need to add a command like "all" or "any" to the first condition or change the && to & (and probably remove that "any" from the second condition).
Note: another source could be Diffpart1 if Diffpart1 is a matrix, as "any" will only operate on one dimension, returning a vector. Telling us the sizes of the arrays you're using in your comparisons will be helpful.

カテゴリ

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

製品

Community Treasure Hunt

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

Start Hunting!

Translated by