Simulink.SimulationData.createStructOfTimeseries

Create a structure with MATLAB timeseries object leaf nodes

Syntax

  • struct_of_ts = Simulink.SimulationData.createStructOfTimeseries(TsArrayObject) example
  • struct_of_ts = Simulink.SimulationData.createStructOfTimeseries(busObj,structOfTimeseries) example
  • struct_of_ts = Simulink.SimulationData.createStructOfTimeseries(busObj,cellOfTimeseries)
  • struct_of_ts = Simulink.SimulationData.createStructOfTimeseries(busObj,cellOfTimeseries,dims) example

Description

example

struct_of_ts = Simulink.SimulationData.createStructOfTimeseries(TsArrayObject) creates a structure of MATLAB® timeseries objects from a Simulink.TsArray object. Use this syntax for models that use the ModelDataLogs signal logging format.

example

struct_of_ts = Simulink.SimulationData.createStructOfTimeseries(busObj,structOfTimeseries) creates a structure that matches the attributes of the bus object busObj and sets the values of structure leaf nodes using a structure of MATLAB timeseries objects structOfTimeseries. Use this syntax when using a partial structure as the basis for creating a full structure to load into a model.

struct_of_ts = Simulink.SimulationData.createStructOfTimeseries(busObj,cellOfTimeseries) creates a structure that matches the attributes of the bus object busObj and sets the values of structure leaf nodes using a cell array of MATLAB timeseries objects cellOfTimeseries.

example

struct_of_ts = Simulink.SimulationData.createStructOfTimeseries(busObj,cellOfTimeseries,dims) creates a structure with the dimensions dims. Use this syntax to create a structure to load into an array of buses.

Examples

expand all

Structure Based on Simulink.TsArray

Log signal data to create a Simulink.TsArray object.

open_system(docpath(fullfile(docroot,'toolbox','simulink','examples',...
'ex_log_modeldatalogs_errwarn')))
sim('ex_log_modeldatalogs_errwarn')

The simulated ex_log_modeldatalogs_errwarn model looks like this:

Use the Simulink.TsArray object to create a structure of MATLAB timeseries objects. The model uses ModelDataLogs format for the signal logging data.

logsout
logsout =
 
Simulink.ModelDataLogs (ex_log_modeldatalogs_errwarn):
  Name                   Elements  Simulink Class

  bus1                      2      TsArray
struct_of_ts = ...
Simulink.SimulationData.createStructOfTimeseries(logsout.bus1)
struct_of_ts = 

    const1-sig: [1x1 timeseries]
    const2_sig: [1x1 timeseries]

Structure Based on Bus Object and a Partial Structure of Timeseries Data

Create a structure of MATLAB timeseries objects based on a Simulink.Bus object and a partial structure of MATLAB timeseriesobjects. Use this structure to load into another model.

Open a model and simulate it, producing signal logging data.

open_system(docpath(fullfile(docroot,'toolbox','simulink',...
'examples','ex_log_structTimeSeries')))
sim('ex_log_structTimeSeries')

The simulated ex_log_structTimeseries model looks like this:

View the logged signal data.

ex_log_structTimeSeries_logsout
ex_log_structTimeSeries_logsout = 

  Simulink.SimulationData.Dataset
  Package: Simulink.SimulationData

  Characteristics:
              Name: 'ex_log_structTimeSeries_logsout'
    Total Elements: 2

  Elements:
    1: 'bus1'
    2: 'bus2'

Open the model to load the logged signal data into.

open_system(docpath(fullfile(docroot,'toolbox','simulink',...
'examples','ex_load_structTimeSeries_Bus')))

The ex_load_structTimeSeries_Bus model's Configuration Parameters > Data Import/Export > Input parameter lists the ex_load_structTimeSeries_inputBus variable. However, you have not yet defined that variable in the MATLAB workspace. Use Simulink.SimulationData.createStructOfTimeseries to define that variable.

ex_load_structTimeSeries_inputBus = ...
Simulink.SimulationData.createStructOfTimeseries...
('bus', ex_log_structTimeSeries_logsout.get(2).Values)
ex_load_structTimeSeries_inputBus = 

    a: [1x1 timeseries]
    b: [1x1 timeseries]

Structure to Use with an Array of Buses

Create a structure of MATLAB timeseries objects to load into an array of buses. Specify the dimensions of the created structure and a cell array of MATLAB timeseries objects.

Open a model and simulate it, producing signal logging data.

open_system(docpath(fullfile(docroot,'toolbox','simulink',...
'examples','ex_log_structTimeSeries')))
sim('ex_log_structTimeSeries')

The simulated ex_log_structTimeseries model looks like this:

View the logged signal data.

ex_log_structTimeSeries_logsout
ex_log_structTimeSeries_logsout = 

  Simulink.SimulationData.Dataset
  Package: Simulink.SimulationData

  Characteristics:
              Name: 'ex_log_structTimeSeries_logsout'
    Total Elements: 2

  Elements:
    1: 'bus1'
    2: 'bus2'

Open the model to load the logged signal data into.

open_system(docpath(fullfile(docroot,'toolbox','simulink',...
'examples','ex_load_structTimeSeries_AoB')))

The ex_load_structTimeSeries_AoB model's Configuration Parameters > Data Import/Export > Input parameter lists the ex_load_structTimeSeries_inputAoB variable. However, you have not yet defined that variable in the MATLAB workspace. Use Simulink.SimulationData.createStructOfTimeseries to define that variable.

ex_load_structTimeSeries_inputAoB = ...
Simulink.SimulationData.createStructOfTimeseries...
('bus',{ex_log_structTimeSeries_logsout.get(1).Values.a,...
ex_log_structTimeSeries_logsout.get(1).Values.b,...
ex_log_structTimeSeries_logsout.get(2).Values.c,...
ex_log_structTimeSeries_logsout.get(2).Values.d},[2, 1])
ex_load_structTimeSeries_inputAoB = 

2x1 struct array with fields:
    a
    b

Input Arguments

expand all

tsArrayObjectSimulink.TsArray object to convertSimulink.TsArray object

Simulink.TsArray object to convert to a structure of MATLAB timeseries objects

When you log signals using the ModelDataLogs format, the logged data is a collection of Simulink.TsArray objects.

busObj — Bus object for creating a structure of MATLAB timeseries objectsSimulink.Bus object

Bus object for creating a structure of MATLAB timeseries objects, specified as the name of a Simulink.Bus object.

Data Types: char

structOfTimeseries — Structure object for values to override ground values, specified as a structure of MATLAB timeseries objects.structure of MATLAB timeseries objects

Structure object for values to override ground values, specified as a structure of MATLAB timeseries objects. The structure must have the same hierarchy as the bus object. However, the names of the fields in the structure do not have to match the names of the corresponding bus object nodes.

Data Types: struct

cellOfTimeseries — Cell array objects for values to override ground values, specified as a cell array of MATLAB timeseries objects.cell array of MATLAB timeseries objects

Cell array object for values to override ground values, specified as a cell array of MATLAB timeseries objects. If you specify a cell array of MATLAB timeseries objects and you specify a dims argument, then the length of the cell array must be equal to the result of Simulink.BusObject.getNumLeafBusElements times the product of the specified dimensions.

Data Types: cell

dims — Dimensions of the structure that this function creates.vector

Dimensions of the structure that this function creates, specified as a vector. The length of the cell array is equal to the result of Simulink.BusObject.getNumLeafBusElements times the product of the specified dimensions.

If you specify a dimension in the form [n], then Simulink® interprets the dimension to be 1xn.

Data Types: double

Output Arguments

expand all

struct_of_ts — Structure of MATLAB timeseries objects.MATLAB structure

MATLAB timeseries objects, returned as a structure. The structure has the same hierarchy and attributes as the Simulink.TsArray object or Simulink.Bus object that you specify.

The dimensions of structForBus depend on the input arguments:

  • If you specify tsArrayObject, then the dimension is 1.

  • If you specify the busObject and a structure of MATLAB timeseries, then the dimension matches the dimensions of the specified structure.

  • If you specify only the busObject and a cell array of MATLAB timeseries, then the dimension is 1.

  • If you specify the busObject argument, a cell array of MATLAB timeseries, and the dims argument, then the dimensions match the dimensions of dims.

Was this topic helpful?