MATLAB Answers


Linearization error "NaN's cannot be converted to logicals"

Asked by Hossein Rezazadeh on 9 Aug 2018
Latest activity Commented on by Tim
on 8 Dec 2018 at 21:14
I get the error. " NaN's cannot be converted to Logicals" when trying to linearize my model. The model runs actually with no problem. the problem arises only when linearizing the model in control design. I don't know what exactly simulink does during linearazation that causes this error.

1 Answer

Answer by Adam Danz
on 9 Aug 2018
 Accepted Answer

This will replicate your error:
v = [1 0 1 1 0 NaN 0 1 0 0];
Error using logical
NaN's cannot be converted to logicals.
My guess is that you're using logical() to convert a variable with 0s and 1s that also have NaN values.
If that's the case, you need to decide whether NaNs should be a 0 or a 1. In this example, I set NaNs to 0.
v = [1 0 1 1 0 NaN 0 1 0 0];
v(isnan(v)) = 0;
Or you can remove the NaNs
v = [1 0 1 1 0 NaN 0 1 0 0];
v(isnan(v)) = [];


Show 1 older comment
As @Walter alluded to in the comment section under your question, you'll need to provide much more detail for us to blindly troubleshoot your problem.
Ok I got it. Apparently during the linearazation some numerical perturbation is fed to the block as input which causes "NAN" at the block output and this was triggering this error. adding v(isnan(v)) = []; to the block output solved the problem.
Hi, could you please explain how exactly you added v(isnan(v)) = []; to the block output?

Sign in to comment.