Access Simulink logging data during a simulation run

1 回表示 (過去 30 日間)
William Stokes
William Stokes 2023 年 5 月 2 日
コメント済み: William Stokes 2023 年 5 月 15 日
Is there a way to programatically access Simulink logged data during a simulation run? (i.e before the simulation has completed)
I am fully aware of the Simulation Data Inspector, which is a nice tool for visualising the data, but in this context I would like to have access to the raw data itself to process in some other way (for example, to send via. HTTP request to an external visualisation tool).
I have been unable to find any documentation that indicates this is possible - all documentation seems to assume the simulation has completed or the output datasets already exist. In this case, my simulation runs for several days, and so accessing the data during the run is important for monitoring. The SDI itself clearly has a way to access the data - I wondered if it was possible utilise whatever method it uses?
thanks

採用された回答

Nathan Hardenberg
Nathan Hardenberg 2023 年 5 月 2 日
This is possible. The Code below shows a possibility to do this with one signal. Obviously you have to replace 'my_model' and 'my_block' appropriately. When getting the data in the loop you can select the Output-Port.
This is only possible, when the signal is actually selected for logging, otherwise an error is thrown.
% Open the Simulink model
open_system('my_model');
% Get real time block object
rto = get_param('my_model/my_block','RuntimeObject');
% Loop until end of simulation
while ~strcmp(get_param('my_model', 'SimulationStatus'), 'stopped')
% Get the logged data
data = rto.OutputPort(1).Data
% Process the data as needed
% ...
% Wait for a short time before checking again
pause(0.1);
end
If you also want to automatically log all signals selected for logging, look here. There is the following code shown. With your own adaptation you should be able to extract all logged signals
mdlsignals = find_system(gcs,'FindAll','on','LookUnderMasks','all',...
'FollowLinks','on','type','line','SegmentType','trunk');
ph = get_param(mdlsignals,'SrcPortHandle')
for i=1: length(ph)
get_param(ph{i},'datalogging')
end
  3 件のコメント
Nathan Hardenberg
Nathan Hardenberg 2023 年 5 月 11 日
Sadly I am not so deep into the topic. For testing I simply used a few basic components where the "Treat as atomic Unit" is not even available.
I also did not know abour rapid accelerator mode before. From googling I found:
"Rapid Accelerator Mode
Rapid accelerator mode creates a rapid accelerator standalone executable from your model. This executable includes the solver and model methods, but it resides outside of MATLAB and Simulink. It uses external mode (see External Mode Communication (Simulink Coder)) to communicate with Simulink." [link]
Since the simulation is extern it seems logical that the implementation may not work. But if the "Simulation Data Inspector" still works there might be another way of getting the data. But as you might guess, I don't know it :D
William Stokes
William Stokes 2023 年 5 月 15 日
No problem, thank you for your help. I suspected that Rapid Accelerator mode might prove an issue because, as you correctly say, it involves externally compiling the model and so accessing stuff at runtime because more difficult.
Thank you again for your help.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeProgrammatic Model Editing についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by