Main Content

Define and Update Inport Data by Using MATLAB Language

You can create root-level input ports and use the MATLAB® language to define input data and to update the input data without rebuilding the model.

Required Files

This procedure has these file dependencies:

  • slrt_ex_osc_inport — Damped oscillator that takes its input data from input port In1 and sends its multiplexed output to output port Out1. To open this model, in the MATLAB Command Window, type:

    open_system(fullfile(matlabroot, 'toolbox', 'slrealtime', ...
    'examples', 'slrt_ex_osc_inport'))
  • slrt_ex_inport_square.mat— One second of output from a Signal Generator block that is configured to output a square wave. To load this data, in the MATLAB Command Window, type:

    (load(fullfile(matlabroot, 'toolbox', 'slrealtime', ...
    'examples', 'slrt_ex_inport_square.mat'))
  • slrt_ex_inport_sawtooth.mat — One second of output from a Signal Generator block that is configured to output a sawtooth wave. To load this data, in the MATLAB Command Window, type:

    (load(fullfile(matlabroot, 'toolbox', 'slrealtime', ...
    'examples', 'slrt_ex_inport_sawtooth.mat'))

Before starting this procedure, navigate to a working folder.

Map Inport to Use Square Wave

This procedure maps an inport.

Open slrt_ex_osc_inport.

model = fullfile(matlabroot, 'toolbox', 'slrealtime', ...
'examples', 'slrt_ex_osc_inport'));
open_system(model);
save_system(model,'H:\workdir\slrt_ex_osc_inport.slx');

Load slrt_ex_inport_square.mat, and then assign square to a temporary workspace variable.

load(docpath(fullfile(docroot, 'toolbox', 'slrealtime', ...
'examples', 'slrt_ex_inport_square.mat')));
waveform = square;

Open slrt_ex_osc_inport/In1

inport = [model '/In1'];
load_system(inport);

Turn off inport data interpolation.

set_param(inport,'Interpolate','off');

Set the external input variable.

set_param(model,'ExternalInput','waveform');

Load external input data.

set_param(model,'LoadExternalInput','on');

You can now build, download, and execute the real-time application.

slbuild(model);
tg = slrealtime('TargetPC1');
load(tg,model);
start(tg);

View the signals in the Simulation Data Inspector.

Simulink.sdi.view;

Update Inport to Use Sawtooth Wave

You can update the inport data to use a different data file without rebuilding the real-time application. The slrt_ex_osc_inport.mldatx file must be in the working folder.

Load slrt_ex_inport_sawtooth.mat, and then assign sawtooth to the temporary variable that you used with the Root Inport Mapper.

load(docpath(fullfile(docroot, 'toolbox', 'slrealtime', ...
'examples', 'slrt_ex_inport_sawtooth.mat')));
waveform = sawtooth;

Create an application object.

app_object = SimulinkRealTime.Application('slrt_ex_osc_inport');

Update the application object.

updateRootLevelInportData(app_object);

Download the updated object to the target computer and execute it.

tg = slrealtime;
load(tg, 'slrt_ex_osc_inport');
start(tg);

View the signals in the Simulation Data Inspector.

Simulink.sdi.view;

Related Topics