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 portIn1
and sends its multiplexed output to output portOut1
. To open this model, in the MATLAB Command Window, type:openExample('slrealtime/SlrtStimulateRootInportByUsingMATLABLanguageExample'); open_system('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('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('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
.openExample('slrealtime/SlrtStimulateRootInportByUsingMATLABLanguageExample'); model = 'slrt_ex_osc_inport'; open_system(model); myFolder = fullfile(userpath,'temp'); save_system(model,[myFolder '/slrt_ex_osc_inport.slx']);
Load
slrt_ex_inport_square.mat
, and then assignsquare
to a temporary workspace variable.load('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 assignsawtooth
to the temporary variable that you used with the Root Inport Mapper.load(('slrt_ex_inport_sawtooth.mat'); waveform = sawtooth;
Create an application object.
app_object = slrealtime.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;
See Also
Target.Stimulation
| Simulink.SimulationData.Dataset