load data of a mdf file to root-level input ports of a simulink model in matlab

To load data from an MDF file to root-level input ports of a Simulink model in Matlab, you can follow the below steps:

  1. Import the MDF file data in Matlab using the "mdfimport" function.
main.m
data = mdfimport('filename.mdf');
34 chars
2 lines
  1. Open the Simulink model and identify the root-level input ports. To add a root-level input port, right-click on the Simulink canvas and select "Add Block > Simulink Library > Sources > In1" (In1 represents the first input port).

  2. Assign the data from the MDF file to the input port using the "From Workspace" block. Drag and drop the "From Workspace" block from the Simulink Library to the Simulink canvas and connect it to the input port.

main.m
FromWorkspaceBlock = add_block('simulink/Sources/From Workspace', '<model_name>/From Workspace');
set(FromWorkspaceBlock, 'VariableName', 'data')
set(FromWorkspaceBlock, 'SampleTime', '-1')
set(FromWorkspaceBlock, 'OutputDataTypeStr', 'double')
245 chars
5 lines
  1. Set the "VariableName" parameter of the "From Workspace" block to the data variable name that you have imported from the MDF file.

  2. Run the Simulink model and the input data will be loaded from the MDF file to the root-level input port of the model.

gistlibby LogSnag