Strange "Compare To Constant" behavior

43 views Asked by At

The behavior of Simulink block Compare To Constant boggles my mind !

figure 1: this simple Simulink model

It doesn't work for the particular value 268.03 but works for other values such as 15.68 as shown below. And I really don't understand why is this the case.

figure 2

For now, I'm able to do what I want by using strings instead as shown below:

figure 3

I still want to understand why the simple Compare To Constant block doesn't work for this particular value (maybe others too that I'm not aware of...).

1

There are 1 answers

3
Likely On

Thanks to @Wolfie's comment I was able to make the model work. enter image description here

where the code inside the Matlab Function block is as follows:

function y = fcn(u)
t = 0.01;

if abs(u - 268.03) < t
    y = 1;
else
    y = 0;
end