Compiled Simulink model giving different results
7 次查看(过去 30 天)
显示 更早的评论
I have a simulink model (.slx) that I am trying to compile and run in Visual Studio. I'm finding that my results are different than the output of the model in simulink. I've tried compiling under C and C++ with identical results.
For example the first few simulink results are 100 97.1696536696777 94.5212838899871 92.0431905150397 89.7244256574844 87.5547453221953
and visual studio: 97.87 95.18 92.66 90.30 88.09 86.03
If I have a 2 minute simulation with .04 time step my Visual Studio results appear to skip the first step and then be shifted left by .03.
Any ideas?
0 个评论
采纳的回答
Guy Rouleau
2013-10-17
I would bet that this is related to the "Single output/update function" parameter. See this doc page:
Look at the bullet starting with "If you have customized ert_main.c or .cpp to read model outputs after each base-rate model step..."
In this page:
http://www.mathworks.com/help/simulink/sfg/how-the-simulink-engine-interacts-with-c-s-functions.html
Look at the Simulation Loop image. The Simulation retunrs values just after the first mdlOutputs. With the generated code, the step function runs everything sothe data you see is at the bottom, when the left arrows goes back up.
Both results are good... they are just at different moments in time.
To see identical results,un check the option mentionned above. In the code, call "output", read your signals, then call update.
0 个评论
更多回答(2 个)
Andreas Goser
2013-10-16
Beside there are multiple ways to "compile and run a model", this is really something where you should contact Technical Support for and include your example.
0 个评论
Matt
2013-10-17
编辑:Matt
2013-10-17
2 个评论
Guy Rouleau
2013-10-17
Three steps... looks like you are using the ode3 solver.
If your model uses ode1, results should match, but accuracy will change.
If you change your model to be fully discrete, results should match.
Inserting a Unit Delay, Rate Transition, or another block that makes your output discrete can make the results match because discrete blocks only execute Output once and Update once.
As you can figure out, those options are changing the simulation so that it generates code that will return identical results. To have more control over the generated control, you need Embedded Coder.
I want to repeat it again to be sure it is clear... the results using you get using GRT are not wrong... they are just extracted from the simulation loop at a different time.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!