Simulink.ModelDataLogs
Container for signal data logs of a model
Description
Note
TheModelDataLogs
class is supported for backwards compatibility. Starting in R2016a, you cannot log data in theModelDataLogs
format. Signal logging uses theDataset
format. In R2016a or later, when you simulate a model from an earlier release that had usedModelDataLogs
format, the model usesDataset
format to log data.
You can convert signal logging data fromModelDataLogs
toDataset
format. Converting toDataset
format can facilitate post-processing with other logged data (for example, logged states), which can also useDataset
format. For more information, seeConvert Logged Data to Dataset Format.
If you have legacy code that usesModelDataLogs
, you can encounter situations that require updates to your code or model. For more information about updating scripts, seeMigrate Scripts That Use Legacy ModelDataLogs API.
In releases before R2016a, when you setConfiguration Parameters>Data Import/Export>Signal logging formattoModelDataLogs
, logging data produces one or moreSimulink.ModelDataLogs
objects that contain logged data. Logging creates an instance of this class for the top model and for each model referenced by the top model that contains logged signals. TheModelDataLogs
object for the top model is assigned to a variable in the base workspace. The name of the variable is specified by theConfiguration Parameters>Data Import/export>Signal logging nameparameter. The default value islogsout
.
AModelDataLogs
对象数量可变的属性。的玩家rst property,Name
指定的名称dat模型的信号a the object contains or, if the model is a referenced model, the name of the Model block that references the model. The remaining properties reference objects that contain signal data logged during simulation of the model. The objects may be instances of these types of objects:
Container for the data logs of a model
Container for the data logs of a subsystem
Data log for any signal except a mux or bus signal
Data log for a mux or bus signal
The names of the properties identify the data being logged as follows:
For signal data logs, the name of the signal
For a subsystem or model log container, the name of the subsystem or model, respectively
Consider, for example, the following model.
As indicated by the testpoint icons, this model specifies that Simulink®software should log the signals namedstep
andscope
in the root system and the signal namedclk
in the subsystem named Delayed Out. After you simulate this model in a release earlier than R2016a, the MATLAB®workspace contains the following variable:
Simulink.ModelDataLogs (siglgex): Name elements Simulink Class scope 2 TsArray step 1 Timeseries ('Delayed Out') 2 SubsysDataLogs
You can use fully qualified object names or the Simulinkunpack
command to access the signal data. For example, to access the amplitudes of theclk
signal in the Delayed Out subsystem in alogsout
object, enter
data = logsout.('Delayed Out').clk.Data;
or
>> logsout.unpack('all'); >> data = clk.Data;
Access Logged Signal Data Saved inModelDataLogs
Format
TheSimulink.ModelDataLogs
object contains signal data objects to capture signal logging information for specific model elements.
Model Element | Signal Data Object |
---|---|
Top-level or referenced model | Simulink.ModelDataLogs |
Subsystem in a model | Simulink.SubsysDataLogs |
Signal other than a bus or Mux signal | Simulink.Timeseries |
Bus signal or Mux signal | Simulink.TsArray |
Handling Spaces and Newlines in Logged Names
Signal names in data logs can have spaces or newlines in their names when the signal:
Is named and the name includes a space or newline character.
Is unnamed and originates in a block whose name includes a space or newline character.
Exists in a subsystem or referenced model, and the name of the subsystem, Model block, or of any superior block includes a space or newline character.
The following model shows a signal whose name contains a space, a signal whose name contains a newline, and an unnamed signal that originates in a block whose name contains a newline:
The following example shows how to handle spaces or new lines in logged names, if a model usesModelDataLogs
for the signal logging format.
logsout
logsout = Simulink.ModelDataLogs (model_name): Name Elements Simulink Class ('x y') 1 Timeseries ('a b') 1 Timeseries ('SL_Sine Wave1') 1 Timeseries
You cannot access any of theSimulink.Timeseries
objects in this log using TAB name completion or by typing the name to MATLAB. This syntax is not recognized because the space or newline in each name appears to the MATLAB parser as a separator between identifiers. For example:
logsout.x y
??? logsout.x y | Error: Unexpected MATLAB expression.
To reference aSimulink.Timeseries
object whose name contains a space, enclose the element containing the space in single quotes:
logsout.('x y')
Name: 'x y' BlockPath: 'model_name/Sine' PortIndex: 1 SignalName: 'x y' ParentName: 'x y' TimeInfo: [1x1 Simulink.TimeInfo] Time: [51x1 double] Data: [51x1 double]
To reference aSimulink.Timeseries
object whose name contains a newline, concatenate to construct the element containing the newline:
cr=sprintf('\n') logsout.(['a'cr'b'])
The same techniques work when a space or newline in a data log derives from the name of:
An unnamed logged signal's originating block
A subsystem or Model block that contains any logged signal
Any block that is superior to such a block in the model hierarchy
This code can reference logged data for the signal:
logsout.(['SL_Sine'cr'Wave1'])
For names with multiple spaces, newlines, or both, repeat and combine the two techniques as needed to specify the intended name to MATLAB.
Bus Signals
ModelDataLogs
format stores each logged bus signal data in a separateSimulink.TsArray
object.
The hierarchy of a bus signal is preserved in the logged signal data. The logged name of a signal in a virtual bus derives from the name of the source signal. The logged name of a signal in a nonvirtual bus derives from the applicable bus object, and can differ from the name of the source signal. SeeComposite Signalsfor information about those capabilities.
See Also
Convert Logged Data to Dataset Format,Migrate Scripts That Use Legacy ModelDataLogs API,Simulink.SubsysDataLogs
,Simulink.Timeseries
,Simulink.TsArray
,who
,whos
,unpack