Main Content

createInputDataset

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

Description

[inDS] = createInputDataset(mdl) generates a Simulink.SimulationData.Dataset object from the top-level Inport blocks 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 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.

[inDS] = createInputDataset(mdl,Name=Value) specifies options using one or more name-value arguments in addition to the input arguments in previous syntaxes. For example, to set the dataset format to timetable, set DatasetSignalFormat=timeseries.

example

Examples

collapse all

This example shows how to create a timeseries 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, 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, "UpdateDiagram", true);
Backing up simulation data to base workspace. To skip this operation, set Export=false.

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.

plot(ds)

Set the Input configuration parameter to ds. Alternatively, you can use the Root Inport Mapper tool to set the Input parameter.

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

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 string, character vector, or model handle.

Name-Value Arguments

collapse all

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Example: DatasetSignalFormat=timeseries

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

Option to turn off update diagram. By default, createInputDataset performs an update diagram for the model.

Note

Turning off update diagram for the model means that the model is not compiled before creating the dataset. While omitting update diagram might improve performance, the new dataset values might not match compiled port settings and might result in simulation errors or inaccurate results.

Output Arguments

collapse all

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

Version History

Introduced in R2017a

expand all