Main Content

createInputDataset

Generate dataset object for root-level Inport or bus element ports in model

Description

example

[inports_dataset] = createInputDataset(model)generates aSimulink.SimulationData.Datasetobject from the root-levelInportblocks or bus element ports in a model. Signals in the generated dataset have the properties of the root inports and the corresponding ground values at model start and stop times. You can createtimetableortimeseriesobjects for the time and values for signals for which you want to load data for simulation. The other signals use ground values.

[inports_dataset] = createInputDataset(model,'DatasetSignalFormat',signalFormat)generates aSimulink.SimulationData.Datasetobject whose signal dataset signal elements are eithertimeseriesortimetable.

Examples

collapse all

This example shows how to create a dataset with elements for the four root-level Inport blocks in a model. Use that dataset as a basis for creating a dataset to load signal data into the model.

The In1 block outputs a double,In2andIn3每个输出nonvirtual总线,andIn4outputs anint16.

mdl ='ex_dataset_for_inports'; open_system(mdl)

Create aDatasetobject for the root-levelInportblocks.

ds = createInputDataset(mdl)
ds = Simulink.SimulationData.Dataset '' with 4 elements Name BlockPath ____ _________ 1 [1x1 timeseries] In1 '' 2 [1x1 struct ] In2 '' 3 [1x1 struct ] In3 '' 4 [1x1 timeseries] In4 '' - Use braces { } to access, modify, or add elements using index.

Replace the placeholder value for the first signal in theDatasetwith actual signal values that you want to load into the model.

ds{1} = ds{1}.delsample('Index',[1,2]); ds{1} = ds{1}.addsample('time',[1 3 3 10]','data',[1 1 5 5]');

Examine theIn2signal.

ds{2}
ans = struct with fields: a: [1x1 timeseries] b: [1x1 timeseries]

ForIn2, create data for bus elementsaandb.

ds{2}.a = ds{2}.a.delsample('Index',[1,2]); ds{2}.a = addsample(ds{2}.a,'time',[1:10]','data',[1:10]'); ds{2}.b = timeseries((1:10)',0.1:.1:1,'Name','sig2_b');

ForIn3, specify data for elementaof the bus, and use ground values for elementb.

ds{3}.a = timeseries((1:10)',0.1:.1:1,'Name','sig3_a');

Plotds.

plot(ds)

Set theInputconfiguration parameter tods. Alternatively, you can use the Root Inport Mapper tool to set theInputparameter.

set_param(mdl,'LoadExternalInput','on'); set_param(mdl,'ExternalInput','ds');

Run the simulation. TheInportblocks use the signal data specified indsor ground values for elements that do not have specified signal data.

sim(mdl)

Input Arguments

collapse all

Model for which to generate a dataset with an element for each root-levelInportblock, specified as a character vector or model handle.

Signal format for dataset signal elements, specified as'timedata'or'timeseries'.

Data Types:char|string

Output Arguments

collapse all

Dataset with an element for each root-levelInportblock, returned as aSimulink.SimulationData.Datasetobject.

Introduced in R2017a