Access Simulink logging data during a simulation run

4 ビュー (過去 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?


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
% 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
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',...
ph = get_param(mdlsignals,'SrcPortHandle')
for i=1: length(ph)
  3 件のコメント
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 についてさらに検索




Community Treasure Hunt

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

Start Hunting!

Translated by