while statements - imposing two conditions

2 visualizaciones (últimos 30 días)
Bran
Bran el 1 de Jul. de 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

Respuestas (2)

Jonathan Sullivan
Jonathan Sullivan el 1 de Jul. de 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 el 1 de Jul. de 2013
Editada: Evan el 1 de Jul. de 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.

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by