outputs of generated code are NAN

Hello, I did code generation of PD Controller. And when I set inputs(thetad, phid, psid, zd), I always get NAN in outputs. Who has similar situation?
Thanks!

Respuestas (1)

John D'Errico
John D'Errico el 25 de Jun. de 2018
Editada: John D'Errico el 25 de Jun. de 2018
The crystal ball is so foggy today. Strange, because it is a nice, sunny day here.
Sorry, but we cannot read your mind, nor can we see into your computer. So how can we know what silly thing you did that generated a NaN? There are lots of ways to create a NaN.
Here are a few common ways to generate a NaN. I recall there are quite a few more ways NaN can result.
0/0
ans =
NaN
inf - inf
ans =
NaN
inf/inf
ans =
NaN
So a NaN results when there is an arithmetic operation with a result that is indeterminate. So while inf+inf just creates another inf, inf-inf is something that arguably could be any value.
And of course, many operations that have a NaN as one of the arguments will result in a NaN. So once you have one NaN, they often propagate, like rabbits.
NaN + 1
ans =
NaN
So, you want to learn about the debugger. You can set it to stop when it sees a problem arise.
dbstop if infnan
Then you need to look at the line in question. What did you do that caused this event?

1 comentario

Rui Shi
Rui Shi el 26 de Jun. de 2018
Editada: Rui Shi el 26 de Jun. de 2018
I did code generation, so codes are in C language. I guess may be there are four feedbacks(phi,psi,theta,z), so the result will be NAN if sample time is infinite. So, do you know how to set step time and sample time to only get twice results?

Iniciar sesión para comentar.

Categorías

Productos

Preguntada:

el 25 de Jun. de 2018

Comentada:

el 26 de Jun. de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by