필터 지우기
필터 지우기

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 CenterFile Exchange에서 Programmatic Model Editing에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by