How to log simulink to file at every sample?

2 visualizaciones (últimos 30 días)
Piotr Kluczek
Piotr Kluczek el 24 de Ag. de 2022
Comentada: Nikhilesh el 14 de Sept. de 2022
I am trying to make Simulink log the simulation logs into a file at every simulation step.
The tools I found (To File block, "Log Dataset data to file" in Configuration Parameters) let me save logs to the file. They do create specified files at the beginning of the simulation but data can be read only at the end. I checked that out by running the simulation and aborting Matlab via Task Manager.
Due to Simulink freezing at some point (probably some 3rd party tool issue, not this issue scope) I cannot get to the end and need to abort Matlab. Hence I receive unreadable file (it gains weight during simulation but seems empty when opened by Matlab), or the proper structure with 0 element timeseries.
  1 comentario
Nikhilesh
Nikhilesh el 14 de Sept. de 2022
In case of Simulink Real-Time applications when running in 'External' simulation mode, the best way to log the data is to use the 'Scope' block from the 'Simulink Real Time' libraries instead of Simulink libraries. Following documentation provides more information on this block
Now, modify the following option the 'Simulink Real Time Scope' block to achieve desired results
  • Select 'Scope type' drop down to 'File'
  • Enter the value in the 'Decimation' filed. How decimation works here is, let us take, the 'Fixed-step size (fundamental sample time)' in the 'Model Configurations -> Solver -> Addition parameters' section is 0.00025 and 'Stop time' is 10. If we log data with 'Decimation' as 1 then the logged file consists of 40001 points (10/0.00025 = 40000 + 1) and if the we log data with 'Decimation' as 10 then the logged file consists of 4001 points (10/0.00025/10 = 40000/10 + 1).
  • Enter 'Filename' field. Let us take, 'data1.dat' is the file name that consists of logged data
After providing the above information, use the following commands to bring that file to host machine
>> tg.start; % to check if the target is connected or not
>> SimulinkRealTime.copyFileToHost('data1.dat')
>> SimulinkRealTime.utils.getFileScopeData('data1.dat')

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Prepare Model Inputs and Outputs en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by