Simulink While Loop - recording iteration-by-iteration parameters

5 次查看(过去 30 天)
Per the title I am trying to record the evolution of parameters over While loop iterations by writing to a signal or workspace variable for later processing. It is clear that only the final states are available outside the While executed susbsystem.
My approach so far is to try and write some n-length vector of parameters vs iteration number as part of the While iteration. This vector would then be available when the While exits - recording the history.
The issue appears to be that in Simulink the signal widths/sizes need to be known at compile time, however I have no a priori knowledge of how many While iterations will run. This seems to be a fundamental problem that means I can't use the Assignment block, and I can't write a custom MATLAB function that outputs a signal (which could then be passed to the workspace)
It strikes me that if I could write directly to the workspace from inside a MATLAB fcn block I might circumvent the fixed widths of Simulink signals.
Perhaps somebody knows a way to do this?
Or perhaps my whole approach is wrong?
Thanks in advance for any pointers

回答(1 个)

Preethi
Preethi 2018-10-4
hi,
Have you tried using assignin() function?
  1 个评论
Al
Al 2018-10-4
Hi Preethi
Thanks for the suggestion. I'm just testing within simulink at the moment. It throws the following error:
Function 'assignin' is not supported for code generation. Consider adding coder.extrinsic('assignin') at the top of the function to bypass code generation.
This is ultimately going to be for an embedded application so I need a solution compatible with code generation.
At any rate matlab seems really unhappy about any dynamic growing or creation of variables from a MATLAB fcn in the simulink environment. Even if I add the recommended coder.extrinsic line I still cannot append values to a vector.
It should be possible though, as "tout" definitely grows...
Thanks

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Test Model Components 的更多信息

产品


版本

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by