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!

回答(1 个)

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 个评论

Rui Shi
Rui Shi 2018-6-26
编辑:Rui Shi 2018-6-26
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?

请先登录,再进行评论。

类别

在 帮助中心 和 File Exchange 中查找有关 Logical 的更多信息

产品

提问:

2018-6-25

评论:

2018-6-26

Community Treasure Hunt

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

Start Hunting!

Translated by