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

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.

 채택된 답변

Adam Danz
Adam Danz 2018년 8월 9일
This will replicate your error:
v = [1 0 1 1 0 NaN 0 1 0 0];
logical(v)
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;
logical(v)
Or you can remove the NaNs
v = [1 0 1 1 0 NaN 0 1 0 0];
v(isnan(v)) = [];
logical(v)

댓글 수: 4

The model runs actually with no problem. the problem arises only when linearizing the model in control design. So I don't think there is any problem with my code. Besides I am not converting anything to logical in my code. I don't know what exactly simulink does during linearazation that causes this error.
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?

댓글을 달려면 로그인하십시오.

추가 답변 (3개)

Barton Bacon
Barton Bacon 2023년 10월 24일

1 개 추천

This just happened to me and the culprit was a square root block I had recently added to a simulation.... believe it or not. Changing the square root block to a power block and using .5 as the exponent for some reason allowed the linearization to proceed without the "NaN's cannot be converted into logicals" error. MATHWORKS what the heck is going on in the square root and reciprocal square block that would produces this problem in linearization? Those blocks linearize fine by themshelves in a their own block diagram. In a complicated simulation, not so much apparently.
Welid Benchouche
Welid Benchouche 2019년 1월 4일

0 개 추천

hello guys, can you please help me , i get the same error on model predictive control when linearizing Rc=0.15

댓글 수: 2

Hossein Rezazadeh
Hossein Rezazadeh 2019년 1월 4일
편집: Hossein Rezazadeh 2019년 1월 4일
This happens in MPC when your model sends "NaN" to the "mo" inport of the MPC block.
As you have integrators in your model they should be responsible for "NaNs".
Either change the operating point at which you are linearizing the model or change the solver or max step size.
please kindly explain "integrators in your model they should be responsible for "NaNs" "
How are integrators setting for response the NaN value ?
My problem is appear in mpc toolbox when linearize of toolbox.
Thankyou.

댓글을 달려면 로그인하십시오.

Ahmed Elgohary
Ahmed Elgohary 2022년 3월 5일
편집: Ahmed Elgohary 2022년 3월 5일

0 개 추천

Well, i got the same error with model predictive control during linearization and i could solve the problem by changing the range of simulink operating point as shown at the figure. So it was from [0 1] and i made it from [0.1 1] for example as you want for the upper limit but the main problem was related to using zero for lower limit during the linearization.

카테고리

도움말 센터File Exchange에서 Controller Creation에 대해 자세히 알아보기

질문:

2018년 8월 9일

답변:

2023년 10월 24일

Community Treasure Hunt

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

Start Hunting!

Translated by