Why do I receive a given error?

8 views (last 30 days)
Vaibhav Payghan
Vaibhav Payghan on 29 Mar 2024
Edited: Torsten on 29 Mar 2024
if (((Motor_Speed)<=(SleepSpeedThreshold_int_dbl))&&(Tref_Ramp ==0))
timer_KeyOFF = timer_KeyOFF + 0.01;
else
timer_KeyOFF =0;
end
For above code getting a given error
Expected a scalar. Non-scalars are not supported with logical operators. Instead, use ALL to convert matrix logicals to their scalar equivalents. State 'KeyOFF' in Chart 'State_Machine/Control Algorithm': if (((Motor_Speed)<=(SleepSpeedThreshold_int_dbl))&&(Tref_Ramp ==0))

Answers (1)

Torsten
Torsten on 29 Mar 2024
Edited: Torsten on 29 Mar 2024
According to the error message, MotorSpeed, SleepSpeedThreshold_int_dbl and/or Tref_Ramp are arrays, not scalars.
So if you want to have all elements of Motor_Speed to be smaller or equal than the corresponding elements of SleepSpeedThreshold_int_dbl and all elements of Tref_Ramp to be equal to 0, use
if all(Motor_Speed(:) <= SleepSpeedThreshold_int_dbl(:)) & all(Tref_Ramp(:) == 0)

Community Treasure Hunt

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

Start Hunting!