Documentation

Simulink.SimulationData.createStructOfTimeseries

Create structure oftimeseriesdata to load as simulation input for bus

Description

example

tsStruct= Simulink.SimulationData.createStructOfTimeseries(busObj,tsStructIn)creates a structure with attributes that match those specified by theSimulink.Busobject,busObj, and data specified by the structure oftimeseries对象,tsStructIn.

When the names in the input structure do not match the names specified by the bus object, the function renames the fields in the output structure to match the bus object specification. When other attributes such as data type and complexity do not match, the function returns an error.

You can use this syntax to create a simulation input that fully or partially specifies the data for a bus. You can also use this syntax to rename the structure elements to match the names in theSimulink.Busobject.

example

tsStruct= Simulink.SimulationData.createStructOfTimeseries(busObj,tsCellArray)creates a structure oftimeseries对象with attributes that match those specified by theSimulink.Busobject,busObj, and data specified by the cell array oftimeseries对象,tsCellArray.

When the names in the input structure do not match the names specified by the bus object, the function renames the fields in the output structure to match the bus object specification. When other attributes such as data type and complexity do not match, the function returns an error.

You can use this syntax to create simulation input that fully or partially specifies the data for a bus using a flat list oftimeseries对象. The function maps thetimeseries对象to the hierarchy specified by theSimulink.Busobject using a depth-first search.

example

tsStructArray= Simulink.SimulationData.createStructOfTimeseries(busObj,tsCellArray,dims)creates an array oftimeseriesstructures where the attributes of each structure match those defined by theSimulink.Busobject,busObjwith the data specified by the cell array oftimeseries对象,tsCellArray. The inputdimsspecifies the dimensions of the array.

example

tsStruct= Simulink.SimulationData.createStructOfTimeseries(tsArray)creates a structure oftimeseries对象from the bus data stored in theSimulink.TsArrayobject,tsArray. In versions before R2016a, signal logging createsSimulink.TsArray对象to store logged bus data. Use this syntax when you want to use bus data logged in a release before R2016a usingModelDataLogsformat as simulation input.

Examples

collapse all

You can use theSimulink.Simulationdata.createStructOfTimeseriesfunction to create structures oftimeseries对象to use as simulation input for bus signals. This example shows you how to create a structure of timeseries to load into a model using timeseries data logged from a different simulation.

Create a Structure of Timeseries

Open theex_log_structtimeseriesmodel.

open_system('ex_log_structtimeseries')

The model uses Constant blocks and Bus Creator blocks to build two buses,bus1andbus2, with signalsa,b,c, andd. The model uses signal logging to log the bus data. Create bus data by simulating the model.

out = sim('ex_log_structtimeseries');

View the data in the logging variablelogsout. Signal logging creates aSimulink.SimulationData.Datasetobject withSimulink.SimulationData.Signal对象as elements.

logsout = out.logsout
logsout = 金宝appSimulink.SimulationData.Dataset ' logsout' with 2 elements Name BlockPath ____ ____________________________________ 1 [1x1 Signal] bus1 ex_log_structtimeseries/Bus Creator 2 [1x1 Signal] bus2 ex_log_structtimeseries/Bus Creator1 - Use braces { } to access, modify, or add elements using index.

You can use thegetfunction to select theSimulink.SimulationData.Signalobject forbus2. The bus data is in theValuesproperty of theSimulink.SimulationData.Signalobject. The data representingbus2is logged in a structure containingtimeseries对象namedcandd.

logsout.get(2).Values
ans = struct with fields: c: [1x1 timeseries] d: [1x1 timeseries]

Loading Model Configuration

Open theex_load_structtimeseriesmodel, which uses the logged simulation data as input.

open_system('ex_load_structtimeseries')

The model uses theInBus轮廓尺寸块加载输入总线数据。一辆公共汽车Selector block chooses signals from the bus to display on Display blocks.

Double-click theInBusblock and check itsData typeon theSignal Attributestab of the dialog. The data type is specified by aSimulink.Busobject calledbus.

Close the dialog and open the Model Explorer. On theCallbackstab, you can see the model uses itsPreLoadFcnto define theSimulink.Busobject that defines the data type for the Inport block.

Open the Configuration Parameters and view the specification for theInputparameter on theData Import/Exportpane. The model uses the variableinputBusfor itsInput.

Create Simulation Input from the Structure oftimeseriesData

To load the data logged forbus1, you only need to assign the structure data to the Input variable for the model.

inputBus = logsout.get(1).Values
inputBus = struct with fields: a: [1x1 timeseries] b: [1x1 timeseries]

When you simulate the model, the Display blocks show the values1and2logged inbus1and loaded into the model.

To load the data logged forbus2, you need to use theSimulink.Busobject that defines the Inport block data type andSimulink.SimulationData.createStructOfTimeseriesto create a structure oftimeserieswith names specified by theSimulink.Busobject.

inputBus = Simulink.SimulationData.createStructOfTimeseries('bus',...logsout.get(2).Values)
inputBus = struct with fields: a: [1x1 timeseries] b: [1x1 timeseries]

When you simulate the model, the Display blocks show the values3and4logged inbus2and loaded into the model.

This example shows how to use theSimulink.SimulationData.createStructOfTimeseriesfunction to create partially specified simulation input for a bus. This example logs data fromex_log_structtimeseriesand then loads that data intoex_load_structtimeseries.

CreatetimeseriesData

First, open and simulate theex_log_structtimeseriesmodel. The model logs two bus signals,bus1andbus2, created using Constant blocks and Bus Creator blocks. Access thelogsoutDatasetin theSimulink.SimulationOutputobject,out.

open_system('ex_log_structtimeseries') out = sim('ex_log_structtimeseries'); logsout = out.logsout;

You can use a structure oftimeseriesdata or a cell array oftimeseriesdata to partially specify simulation input for a bus.

Partially Specify Bus Data with a Structure oftimeseriesData

Open the modelex_load_structtimeseriesthat will load some of the data you logged in the previous section.

open_system('ex_load_structtimeseries')

Use thegetfunction to access the structure oftimeseriesdata logged forbus1.

bus1 = logsout.get(1).Values;

Then, replace thebdata with[].

bus1.b = [];

Theex_load_structtimeseriesmodel uses the variableinputBusas itsInput. TheSimulink.Busobject,bus, that defines the data type for the Inport block is defined in thePreLoadFcncallback for theex_load_structtimeseriesmodel. Because the signal names inbus1match theSimulink.Busobject specification for the Inport block in theex_load_structtimeseriesmodel, you can use the logged structure without modification. To load the data forbus1, assignbus1to the variableinputBus.

inputBus = bus1;

Simulate the model. The Display blocks show the logged value1foraand0forb. The simulation uses ground values when you do not specify data for the signal.

loadOut = sim('ex_load_structtimeseries');

Now, load the data logged forbus2. The signal names inbus2do not match theSimulink.Busobject specification for the Inport block in theex_load_structtimeseriesmodel. Modify the data in the structure to partially specify input data for the bus. Then, use theSimulink.SimulationData.createStructOfTimeseriesfunction to change the names in the structure to match the bus specification.

bus2 = logsout.get(2).Values; bus2.d = []; inputBus = bus2; inputBus = Simulink.SimulationData.createStructOfTimeseries('bus',inputBus);

Simulate the model. The Display blocks show the logged value3foraand0forb.

loadOut = sim('ex_load_structtimeseries');

Partially Specify Bus Data with a Cell Array of Timeseries Data

When you havetimeseriesdata, you can useSimulink.SimulationData.createStructOfTimeseriesto partially specify simulation input for a bus using a cell array of thetimeseriesdata. Load thetimeseriesdata for signaldinbus2as part of a partial bus specification for the Inport block in theex_load_structtimeseriesmodel. ThePreLoadFcncallback for theex_load_structtimeseriesmodel defines theSimulink.Busobject,bus, that defines the data type for the Inport block.

d = logsout.get(2).Values.d; inputBus = Simulink.SimulationData.createStructOfTimeseries('bus',...{d,[]});

Simulate the model. The Display block for signalain theex_load_structtimeseriesmodel shows the data logged in signaldfrom theex_log_structtimeseriesmodel. The Display block for signalbshows0.

loadOut = sim('ex_load_structtimeseries');

This example shows how to use theSimulink.SimulationData.createStructOfTimeseriesfunction to generate simulation input for an array of buses. You createtimeseriesdata by simulating one model. Then, you create an input structure using the logged data to load into an array of buses in another model.

CreatetimeseriesData

To start, open theex_log_structtimeseriesmodel.

open_system('ex_log_structtimeseries')

The model creates two buses,bus1andbus2, using Constant blocks and Bus Creator blocks. The signals are nameda,b,c, andd. Create logged bus data by simulating the model.

out = sim('ex_log_structtimeseries');

The outputoutcontains aSimulink.SimulationData.Datasetobject,logsout, with the logged data. You can access thebus1andbus2signals using thegetfunction. The data for each signal is in theSimulink.SimulationData.SignalobjectValuesparameter. You can access the bus elements using a dot followed by the signal name.bus1is the first signal in theDatasetobject and contains signalsaandb.bus2contains signalscandd.

logsout = out.logsout; a = logsout.get(1).Values.a; b = logsout.get(1).Values.b; c = logsout.get(2).Values.c; d = logsout.get(2).Values.d;

Loading Model Configuration

Open the modelex_structtimeseries_aob, which uses an array of buses as input.

open_system('ex_load_structtimeseries_aob')

The model uses theInAoBInport block to load simulation input. Selector blocks select a bus from the array of buses, and Bus Selector blocks select signals to show in the Display blocks.

Double-click theInAoBblock and look at theSignal Attributespane of the dialog. TheData typefor the block is set toBuswith the type defined by theSimulink.Busobject,bus. ThePort dimensionsparameter is set to[2 1].

You can see the definition for theSimulink.Busobject,bus, in theCallbackstab in the Model Explorer. This model uses thePreLoadFcnto define the bus object.

Open the Model Configuration Parameters and look at theInputparameter. The model uses the variableinputAoBas input.

Create Array of Buses Simulation Input

UseSimulink.SimulationData.createStructOfTimeseriesand the data logged in the first section to create a structure to load as simulation input for the array of buses. Specify the dimensions as[2 1]to match the dimensions of theInAoBblock.

inputAoB = Simulink.SimulationData.createStructOfTimeseries('bus',...{a,b,c,d},[2 1]);

When you simulate the model, the Display blocks show the data for signalsa,b,c, anddlogged from theex_log_structtimeseriesmodel. The array of buses contains two buses with signalsaandb.Simulink.SimulationData.createStructOfTimeseriesrenamed signalscanddto match theSimulink.Busspecification used by the array of buses.

inputAoB(2)
ans = struct with fields: a: [1x1 timeseries] b: [1x1 timeseries]

Simulate the model. The display blocks show the logged values.

aob_out = sim('ex_load_structtimeseries_aob');

In releases before R2016a, when you log simulation data usingModelDataLogsformat, bus data is stored as aSimulink.TSArrayobject. You cannot log data usingModelDataLogsformat using a release after R2016a. In this example, the logged data,logsout, was logged inModelDataLogsformat using a release before R2016a. The variablelogsoutcontains data for a single bus,bus1.

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

To load the logged data as simulation input for a bus, create a structure oftimeseries对象from the data inbus1.

struct_of_ts =...Simulink.SimulationData.createStructOfTimeseries(logsout.bus1)
struct_of_ts = const1_sig: [1x1 timeseries] const2_sig: [1x1 timeseries]

Input Arguments

collapse all

Name of theSimulink.Busobject that specifies the attributes for the data in the output structure oftimeseries对象. When you want to load the structure oftimeseries对象as simulation input for a bus, thebusObjis the bus that defines the data type for the root-levelInportblock.

Simulink.SimulationData.createStructOfTimeseriesvalidates the inputtimeseries属性cluding data type and complexity against theSimulink.Busobject specification. When element names do not match between theSimulink.Busspecification and the inputtimeseriesdata,Simulink.SimulationData.createStructOfTimeseriesrenames thetimeseriesdata to match the bus specification. When other attributes do not match, the function returns an error.

Example:'MyInputBus'

Structure oftimeseriesdata for use in creating the output structure oftimeseries对象according to theSimulink.Busobject. The structure must have the same hierarchy as theSimulink.Busobject.

To partially specify data for a bus, use[]in the place of the bus element you want to use ground values.

Cell array oftimeseries对象specifying the data for the output structure oftimeseries对象.

To partially specify data for a bus, use[]in the place of the bus element you want to use ground values.

TheSimulink.SimulationData.createStructOfTimeseriesfunction maps thetimeserieselements of the cell array to the hierarchy specified by theSimulink.Busobject using a depth-first search.

Example:{ts1,ts2,ts3}

Example:{ts1,[],ts3}

Dependencies

When you specify thedimsargument, the number of cells in the cell array must match the number of individual signal elements in theSimulink.Busobject multiplied by the product of the specified dimensions.

Dimensions for the array oftimeseriesstructures, specified as a vector.

When you specify the dimensions as a scalar,n, the function creates a1-by-narray.

Example:[2,1]

Dependencies

When you specify thedimsargument, the number of cells in the cell array must match the number of individual signal elements in theSimulink.Busobject multiplied by the product of the specified dimensions.

Data Types:double

Simulink.TsArrayobject.

In versions prior to R2016a, signal logging createsSimulink.TsArray对象to store logged bus data. Use this syntax when you want to use data logged usingModelDataLogsformat in a version before R2016a to create simulation input for a bus.

Example:myTsArrayObj

Output Arguments

collapse all

Structure oftimeseries对象with attributes specified by theSimulink.TsArrayorSimulink.Businput. You can load the structure oftimeseries对象as simulation input for a bus.

Array of structures oftimeseries对象with dimensions specified by thedimsinput.

Introduced in R2013a