Documentation

createInputDataset

Generate dataset object for root-level Inport blocks in model

Syntax

[inports_dataset] = createInputDataset(model)

Description

example

[inports_dataset] = createInputDataset(model) generates a Simulink.SimulationData.Dataset object from the root-level Inport blocks 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 create timetable or timeseries objects for the time and values for signals for which you want to load data for simulation. The other signals use ground values.

Examples

collapse all

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.

Open the model. The In1 block outputs a double, In2 and In3 each output a nonvirtual bus, and In4 outputs an int16.

mdl = 'ex_dataset_for_inports';
open_system(mdl)

Create a Dataset object for the root-level Inport blocks.

ds = createInputDataset(mdl)
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 the Dataset with 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 the In2 signal.

ds{2}
ans = 

  struct with fields:

    a: [1×1 timeseries]
    b: [1×1 timeseries]

For In2, create data for bus elements a and b.

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

For In3, specify data for element a of the bus, and use ground values for element b.

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

Plot ds. For more information, see the Simulink.SimulationData.Dataset.plot documentation.

plot(ds)

Set the Input configuration parameter to ds.

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

Tip

Alternatively, you can use the Root Inport Mapper tool to set the Input parameter. For details, see Map Root Inport Signal Data.

Run the simulation. The Inport blocks use the signal data specified in ds or 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-level Inport block, specified as a character vector or model handle.

Output Arguments

collapse all

Dataset with an element for each root-level Inport block, returned as a Simulink.SimulationData.Dataset object.

Introduced in R2017a

Was this topic helpful?