getInputString

Create comma-separated list of variables to map

Syntax

  • externalInputString = getInputString(inputmap,'base') example
  • externalInputString = getInputString(inputmap,filename) example

Description

example

externalInputString = getInputString(inputmap,'base') creates an input string using the supplied mapping inputmap and the variables loaded in the base workspace ('base').

This function generates a comma-separated list of variables (input string) to be mapped. You can then use this list:

  • As input to the sim command. Load the variables in the base workspace first.

  • As input for the Configuration Parameters > Data Import/Export > Input parameter. Copy the contents of the input string into the text field.

This function is most useful if you have created a custom mapping.

example

externalInputString = getInputString(inputmap,filename) creates an input string using the supplied mapping inputmap and the variables defined in filename.

Examples

expand all

Create an input string from the base workspace

Create an input string from the base workspace and simulate a model.

Open the model

slexAutotransRootInportsExample;

Create signal variables in the base workspace

Throttle = timeseries(ones(10,1)*10);
Brake    = timeseries(zeros(10,1));

Create a mapping (inputMap) for the model.

inputMap = getRootInportMap('model',...
'slexAutotransRootInportsExample',...
'signalName',{'Throttle','Brake'},...
'blockName',{'Throttle','Brake'});

Call getInputString with inputMap and 'base' as inputs.

externalInputString = getInputString(inputMap,'base')
externalInputString =

Throttle,Brake

Simulate the model with the input string.

sim('slexAutotransRootInportsExample','ExternalInput',...
externalInputString);

Create an external input string from variables in a MAT-file

Create an external input string from variables in a MAT-file named input.mat.

In a writable folder, create a MAT-file with input variables.

Throttle = timeseries(ones(10,1)*10);
Brake    = timeseries(zeros(10,1));
save('input.mat','Throttle','Brake');

Open the model.

slexAutotransRootInportsExample;

Create map object.

inputMap = getRootInportMap('model',...
'slexAutotransRootInportsExample',...
'signalName',{'Throttle','Brake'},...
'blockName',{'Throttle','Brake'});

Get the resulting input string.

externalInputString = getInputString(inputMap,'input.mat')
externalInputString =

Throttle,Brake

Load variables from the base workspace for the simulation.

load('input.mat');

Simulate the model.

sim('slexAutotransRootInportsExample','ExternalInput',...
externalInputString);

Alternatively, if you want to input the list of variables through the Configuration Parameters dialog, copy the contents of externalInputString (Throttle,Brake) into the Data Import/Export > Input parameter. Apply the changes, and then simulate the model.

Input Arguments

expand all

inputmap — Map objectstring

Map object, as returned from the getRootInportMap function.

filename — Input variablesMAT-file name as string

Input variables, contained in a MAT-file. The file contains variables to map.

Example: 'data.mat'

Data Types: char

Output Arguments

expand all

externalInputString — External input string Comma-separated string

External input string, returned as a comma-separated string. The string contains root inport information that you can specify to the sim command or the Configuration Parameters > Data Import/Export > Input parameter.

Was this topic helpful?