+ or - Bias Based on < or >
Mostrar comentarios más antiguos
I am attempting to add or subtract a bias value based on weither variable AccelLateral_PT is less or greater than AccelLat. The resulting Corrected_Lateral_Accel for the code below is only resulting in the addition of the bias value. Could anyone help? Thank you.
load('Lateral_Accel_Data')
if AccelLateral_PT > AccelLateral
Corrected_Lateral_Accel = AccelLateral_PT - Lateral_Accel_Bias;
else
Corrected_Lateral_Accel = AccelLateral_PT + Lateral_Accel_Bias;
end
Respuestas (1)
Steven Lord
el 10 de Dic. de 2020
0 votos
I suspect at least one of AccelLateral_PT and AccelLateral is not scalar. From the documentation page for the if keyword: "An expression is true when its result is nonempty and contains only nonzero elements (logical or real numeric). Otherwise, the expression is false." Because of this, you will only subtract the bias if every element of AccelLateral_PT is greater than AccelLateral. If even one element is not, the else block is executed.
Categorías
Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!