map data to root-level input ports of a simulink model in matlab

To map data to root-level input ports of a Simulink model in MATLAB:

  1. Load your Simulink model into MATLAB using the load_system command.
main.m
load_system('myModel');
24 chars
2 lines
  1. Get handles to the root-level input ports of the model using the get_param command.
main.m
inPortHandles = get_param('myModel','input') % get handles to all input ports
78 chars
2 lines

If you have multiple input ports in your model, you can access each input port handle by indexing inPortHandles with the corresponding port number.

  1. Create a data object containing the input data that you want to map to the input port.
main.m
inputData = [1 2 3 4];
23 chars
2 lines
  1. Map the data to the input port handle using the set_param command.
main.m
set_param(inPortHandles(1),'Data', 'inputData');
49 chars
2 lines

This will map the inputData variable to the first input port of the model.

Repeat steps 3-4 for each input port in your model as needed.

  1. Run the simulation to apply the input data to the model.
main.m
sim('myModel');
16 chars
2 lines

gistlibby LogSnag