Documentation

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 signal logging data for a model simulated in a release earlier than R2016a that used 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

collapse all

Suppose you had signal logging data from simulating a model in a release earlier than R2016a, using the ModelDataLogs format. The logged output is logsout.

View the logged data.

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

  bus1                      2      TsArray

Convert the logged data to a structure of MATLAB timeseries objects.

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

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

Create a structure of MATLAB timeseries objects based on a Simulink.Bus object and a partial structure of MATLAB timeseries objects. Use this structure to load into another model. Open a model and simulate it, producing signal logging data.

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')

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 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]

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

collapse all

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

In releases earlier than R2016a, when you log signals using the ModelDataLogs format, the logged data is a collection of Simulink.TsArray objects.

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

Data Types: char

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

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

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

collapse all

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 structOfTimeseries depend on the input arguments:

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

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

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

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

Introduced in R2013a

Was this topic helpful?