Simulink.SimulationData.createStructOfTimeseries
Create structure oftimeseries
data to load as simulation input for bus
Syntax
Description
creates a structure with attributes that match those specified by thetsStruct
= Simulink.SimulationData.createStructOfTimeseries(busObj
,tsStructIn
)Simulink.Bus
object,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.Bus
object.
creates a structure oftsStruct
= Simulink.SimulationData.createStructOfTimeseries(busObj
,tsCellArray
)timeseries
对象with attributes that match those specified by theSimulink.Bus
object,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.Bus
object using a depth-first search.
creates an array oftsStructArray
= Simulink.SimulationData.createStructOfTimeseries(busObj
,tsCellArray
,dims
)timeseries
structures where the attributes of each structure match those defined by theSimulink.Bus
object,busObj
with the data specified by the cell array oftimeseries
对象,tsCellArray
. The inputdims
specifies the dimensions of the array.
creates a structure oftsStruct
= Simulink.SimulationData.createStructOfTimeseries(tsArray
)timeseries
对象from the bus data stored in theSimulink.TsArray
object,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 usingModelDataLogs
format as simulation input.
Examples
Use Logged Bus Data as Simulation Input
You can use theSimulink.Simulationdata.createStructOfTimeseries
function 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_structtimeseries
model.
open_system('ex_log_structtimeseries')
The model uses Constant blocks and Bus Creator blocks to build two buses,bus1
andbus2
, 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.Dataset
object 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 theget
function to select theSimulink.SimulationData.Signal
object forbus2
. The bus data is in theValues
property of theSimulink.SimulationData.Signal
object. The data representingbus2
is logged in a structure containingtimeseries
对象namedc
andd
.
logsout.get(2).Values
ans = struct with fields: c: [1x1 timeseries] d: [1x1 timeseries]
Loading Model Configuration
Open theex_load_structtimeseries
model, 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 theInBus
block and check itsData typeon theSignal Attributestab of the dialog. The data type is specified by aSimulink.Bus
object calledbus
.
Close the dialog and open the Model Explorer. On theCallbackstab, you can see the model uses itsPreLoadFcn
to define theSimulink.Bus
object 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 variableinputBus
for itsInput.
Create Simulation Input from the Structure oftimeseries
Data
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 values1
and2
logged inbus1
and loaded into the model.
To load the data logged forbus2
, you need to use theSimulink.Bus
object that defines the Inport block data type andSimulink.SimulationData.createStructOfTimeseries
to create a structure oftimeseries
with names specified by theSimulink.Bus
object.
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 values3
and4
logged inbus2
and loaded into the model.
Partially Specify Simulation Input for a Bus
This example shows how to use theSimulink.SimulationData.createStructOfTimeseries
function to create partially specified simulation input for a bus. This example logs data fromex_log_structtimeseries
and then loads that data intoex_load_structtimeseries
.
Createtimeseries
Data
First, open and simulate theex_log_structtimeseries
model. The model logs two bus signals,bus1
andbus2
, created using Constant blocks and Bus Creator blocks. Access thelogsout
Dataset
in theSimulink.SimulationOutput
object,out
.
open_system('ex_log_structtimeseries') out = sim('ex_log_structtimeseries'); logsout = out.logsout;
You can use a structure oftimeseries
data or a cell array oftimeseries
data to partially specify simulation input for a bus.
Partially Specify Bus Data with a Structure oftimeseries
Data
Open the modelex_load_structtimeseries
that will load some of the data you logged in the previous section.
open_system('ex_load_structtimeseries')
Use theget
function to access the structure oftimeseries
data logged forbus1
.
bus1 = logsout.get(1).Values;
Then, replace theb
data with[]
.
bus1.b = [];
Theex_load_structtimeseries
model uses the variableinputBus
as itsInput. TheSimulink.Bus
object,bus
, that defines the data type for the Inport block is defined in thePreLoadFcn
callback for theex_load_structtimeseries
model. Because the signal names inbus1
match theSimulink.Bus
object specification for the Inport block in theex_load_structtimeseries
model, you can use the logged structure without modification. To load the data forbus1
, assignbus1
to the variableinputBus
.
inputBus = bus1;
Simulate the model. The Display blocks show the logged value1
fora
and0
forb
. 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 inbus2
do not match theSimulink.Bus
object specification for the Inport block in theex_load_structtimeseries
model. Modify the data in the structure to partially specify input data for the bus. Then, use theSimulink.SimulationData.createStructOfTimeseries
function 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 value3
fora
and0
forb
.
loadOut = sim('ex_load_structtimeseries');
Partially Specify Bus Data with a Cell Array of Timeseries Data
When you havetimeseries
data, you can useSimulink.SimulationData.createStructOfTimeseries
to partially specify simulation input for a bus using a cell array of thetimeseries
data. Load thetimeseries
data for signald
inbus2
as part of a partial bus specification for the Inport block in theex_load_structtimeseries
model. ThePreLoadFcn
callback for theex_load_structtimeseries
model defines theSimulink.Bus
object,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 signala
in theex_load_structtimeseries
model shows the data logged in signald
from theex_log_structtimeseries
model. The Display block for signalb
shows0
.
loadOut = sim('ex_load_structtimeseries');
Load Simulation Input Data for an Array of Buses
This example shows how to use theSimulink.SimulationData.createStructOfTimeseries
function to generate simulation input for an array of buses. You createtimeseries
data by simulating one model. Then, you create an input structure using the logged data to load into an array of buses in another model.
Createtimeseries
Data
To start, open theex_log_structtimeseries
model.
open_system('ex_log_structtimeseries')
The model creates two buses,bus1
andbus2
, 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 outputout
contains aSimulink.SimulationData.Dataset
object,logsout
, with the logged data. You can access thebus1
andbus2
signals using theget
function. The data for each signal is in theSimulink.SimulationData.Signal
objectValues
parameter. You can access the bus elements using a dot followed by the signal name.bus1
is the first signal in theDataset
object and contains signalsa
andb
.bus2
contains signalsc
andd
.
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 theInAoB
Inport 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 theInAoB
block and look at theSignal Attributespane of the dialog. TheData typefor the block is set toBuswith the type defined by theSimulink.Bus
object,bus
. ThePort dimensionsparameter is set to[2 1]
.
You can see the definition for theSimulink.Bus
object,bus
, in theCallbackstab in the Model Explorer. This model uses thePreLoadFcn
to define the bus object.
Open the Model Configuration Parameters and look at theInputparameter. The model uses the variableinputAoB
as input.
Create Array of Buses Simulation Input
UseSimulink.SimulationData.createStructOfTimeseries
and 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 theInAoB
block.
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
, andd
logged from theex_log_structtimeseries
model. The array of buses contains two buses with signalsa
andb
.Simulink.SimulationData.createStructOfTimeseries
renamed signalsc
andd
to match theSimulink.Bus
specification 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');
Create a Structure oftimeseries
Objects from aSimulink.TsArray
Object
In releases before R2016a, when you log simulation data usingModelDataLogs
format, bus data is stored as aSimulink.TSArray
object. You cannot log data usingModelDataLogs
format using a release after R2016a. In this example, the logged data,logsout
, was logged inModelDataLogs
format using a release before R2016a. The variablelogsout
contains 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
busObj
—Name ofSimulink.Bus
object
character vector
Name of theSimulink.Bus
object 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, thebusObj
is the bus that defines the data type for the root-levelInportblock.
Simulink.SimulationData.createStructOfTimeseries
validates the inputtimeseries
属性cluding data type and complexity against theSimulink.Bus
object specification. When element names do not match between theSimulink.Bus
specification and the inputtimeseries
data,Simulink.SimulationData.createStructOfTimeseries
renames thetimeseries
data to match the bus specification. When other attributes do not match, the function returns an error.
Example:'MyInputBus'
tsStructIn
—Structure oftimeseries
对象
structure oftimeseries
data
Structure oftimeseries
data for use in creating the output structure oftimeseries
对象according to theSimulink.Bus
object. The structure must have the same hierarchy as theSimulink.Bus
object.
To partially specify data for a bus, use[]
in the place of the bus element you want to use ground values.
tsCellArray
—Cell array oftimeseries
对象
cell array oftimeseries
对象
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.createStructOfTimeseries
function maps thetimeseries
elements of the cell array to the hierarchy specified by theSimulink.Bus
object using a depth-first search.
Example:{ts1,ts2,ts3}
Example:{ts1,[],ts3}
Dependencies
When you specify thedims
argument, the number of cells in the cell array must match the number of individual signal elements in theSimulink.Bus
object multiplied by the product of the specified dimensions.
dims
—Dimensions for output array
vector
Dimensions for the array oftimeseries
structures, specified as a vector.
When you specify the dimensions as a scalar,n
, the function creates a1
-by-n
array.
Example:[2,1]
Dependencies
When you specify thedims
argument, the number of cells in the cell array must match the number of individual signal elements in theSimulink.Bus
object multiplied by the product of the specified dimensions.
Data Types:double
tsArray
—Simulink.TsArray
object
Simulink.TsArray
Simulink.TsArray
object.
In versions prior to R2016a, signal logging createsSimulink.TsArray
对象to store logged bus data. Use this syntax when you want to use data logged usingModelDataLogs
format in a version before R2016a to create simulation input for a bus.
Example:myTsArrayObj
Output Arguments
tsStruct
— Structure oftimeseries
对象
struct
Structure oftimeseries
对象with attributes specified by theSimulink.TsArray
orSimulink.Bus
input. You can load the structure oftimeseries
对象as simulation input for a bus.
tsStructArray
— Array oftimeseries
structures
array
Array of structures oftimeseries
对象with dimensions specified by thedims
input.
See Also
Introduced in R2013a
Open Example
A modified version of this example exists on your system. Do you want to open this version instead?
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select:.
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina(Español)
- Canada(English)
- United States(English)
Europe
- Belgium(English)
- Denmark(English)
- Deutschland(Deutsch)
- España(Español)
- Finland(English)
- France(Français)
- Ireland(English)
- Italia(Italiano)
- Luxembourg(English)
- Netherlands(English)
- Norway(English)
- Österreich(Deutsch)
- Portugal(English)
- Sweden(English)
- Switzerland
- United Kingdom(English)