SimulationMetaData manipulation in Simulink

8 ビュー (過去 30 日間)
Isaac De La Cruz
Isaac De La Cruz 2025 年 6 月 5 日
編集済み: Isaac De La Cruz 2025 年 7 月 4 日
Hello,
I am looking to manipulate the SimulationMetaData property from Simulink.SimulationOutput object.
I am interested in expanding the UserData property to add custom data.
Tried the PostSimFcn property by registering a callback that modifies the output object, and works fine, but when enabling LoggingToFile option on model settings, the modification is not preserved in the *mat file.
At the end, I would like my output mat file containing simulink results (logsout, yout, etc) and SimulationMetaData containing the modifications made.
Any suggestions?
  1 件のコメント
Gayathri
Gayathri 2025 年 6 月 6 日
Can you elaborate more on what function and method you are using. I am asking as when I tried to modify the "UserData" property using "PostSimFcn", I am getting the below error.
Error executing 'PostSimFcn' on SimulationInput object.
Caused by:
Error using postsim
Setting the 'SimulationMetadata' property of class 'Simulink.SimulationOutput' is not supported.

サインインしてコメントする。

採用された回答

Sameer
Sameer 2025 年 7 月 4 日
When "Logging to File" is enabled in Simulink, simulation results are written to the MAT file before any modifications made by "PostSimFcn" are applied. As a result, custom data added in "PostSimFcn" does not appear in the saved file.
As a workaround you can attach custom data after the simulation and then save.
Here's how you can do it:
out = sim(mdl, 'LoggingToFile','on', 'LoggingFileName','out.mat', ...);
out = setUserData(out,myCustomData); % attach your data
save('out_with_metadata.mat','out'); % save combined data+metadata
Hope this helps!
  1 件のコメント
Isaac De La Cruz
Isaac De La Cruz 2025 年 7 月 4 日
編集済み: Isaac De La Cruz 2025 年 7 月 4 日
Hello @Sameer,
Alright! I thought that when the 'LoggingToFile' option is enabled it included also the changes made to the Simulink's output.
Thanks for the clear explanation!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGeneral Applications についてさらに検索

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by