Is there a way to log variables from a Matlab Function Block (in Simulink), that is not output?
17 ビュー (過去 30 日間)
古いコメントを表示
I would like to log variables from a Matlab Function Block (in Simulink) similar to the functionality of a "To Workspace" block saving them in a SimulinkOutput object. As those variables are only internal I cannot connect them to said block. I know, I could simply define them as outputs and only connect them to the "To Workspace" block, but I would like to avoid this work around to keep my model clean (it would be around 10 variables). I have browsed through docu, but could not find something that would solve my issue. So, I am wondering if there is an elegant way to log also variables from a Matlab Function Block (in Simulink) as a an array, like it is possible for signals (connecting them to a "To Workspace" block)?
5 件のコメント
Paul
2024 年 7 月 10 日
I'm pretty sure that global data in Matlab Function blocks in Simulink is quite different than in base Matlab. Here is one relevant doc page: Use Global Data in MATLAB Function Blocks. Not sure if there is a clean way to get a globar variable into the base workspace from a Matlab Function block.
Do you want to log the value of the local variable(s) each time the Matlab Fucntion block executes? Or only the value of the local variable at the time the simulation ends?
採用された回答
Paul
2024 年 7 月 11 日
Here's one option based on the idea of @Aquatris to specify the local variables that you want to log from the Matlab Function as global. Don't know if doing so introduces other risks.
However, as best I can tell this approach uses an undocumented feature, so BUYER BEWARE.
Open the example model used at this doc page. You might want to consider saving the model under a different name.
Open the Model Explorer and navigate to the Model Workspace of the model. There, on the right side of the Model Explorer window you will find the Matlab code that populates the model workspace with the global signal object that's used in the Matlab Function block.
A = Simulink.Signal;
A.DataType = 'double';
A.Dimensions = 1;
A.Complexity = 'real';
A.SamplingMode = 'Sample based';
A.InitialValue = '5';
Add the following line. The LoggingInfo property has other fields that you may want to take a look at. I can't find the LoggingInfo property of a Simulink.Signal in the doc. BUYER BEWARE.
A.LoggingInfo.DataLogging = true;
Simulate the model
slout = sim(....);
and the variable 'A' should show up in slout.dsmout. The variable name 'dsmout' is specified under Model Settings -> Data Import/Export in the Save to Workspace or File list (as long as Data Stores is checked).
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!