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

답변 (1개)

Steven Lord
Steven Lord 2020년 12월 10일

0 개 추천

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.
If my suspicion is correct, you want to use logical indexing instead.

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

질문:

2020년 12월 10일

답변:

2020년 12월 10일

Community Treasure Hunt

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

Start Hunting!

Translated by