Why do I receive a given error?

8 次查看(过去 30 天)
Vaibhav Payghan
Vaibhav Payghan 2024-3-29
编辑: Torsten 2024-3-29
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))

回答(1 个)

Torsten
Torsten 2024-3-29
编辑:Torsten 2024-3-29
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)

类别

Help CenterFile Exchange 中查找有关 NaNs 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by