while statements - imposing two conditions

3 vues (au cours des 30 derniers jours)
Bran
Bran le 1 Juil 2013
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

Réponses (2)

Jonathan Sullivan
Jonathan Sullivan le 1 Juil 2013
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 le 1 Juil 2013
Modifié(e) : Evan le 1 Juil 2013
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.

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by