Extracting Timetables… Simulink style
Today I want to share a simple tip to interact with data logged from a Simulink model
The Problem
Let's take this simple model that logs 3 signals with different sample times:

After simulating, it is possible to use extractTimetable to create a single timetable with all the logged signals:
out = sim('testLog');
TT = out.logsout.extractTimetable
What's the problem? In one word: NaN.
By default, extractTimetable inserts NaN for steps where signals with a sample time slower than the fastest rate did not execute. While this is technically correct because there was no data point at this time, I find this not ideal for data logged from Simulink.
In Simulink, if I was to connect a Rate Transition block and other blocks downstream from this logged signal, they would not receive NaNs. Instead, the previous value would be held.

When plotting the timetable, the NaNs cause gaps in the signals:
stackedplot(TT);
The Solution
To obtain a timetable that I find better aligned with Simulink's behavior, you can first extract the data as a cell array that contains one timetable per signal, and then combine them using the synchronize function:
TT = out.logsout.extractTimetable(OutputFormat="cell-by-signal");
TT = synchronize(TT{:},"union","previous")
This looks better.
stackedplot(TT);
Now it's your turn
Do you prefer the default behavior of extractTimetable? Would you prefer if the "zero-order hold" behavior shown in this post was the default? Let us know in the comments below.
댓글
댓글을 남기려면 링크 를 클릭하여 MathWorks 계정에 로그인하거나 계정을 새로 만드십시오.