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:

    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.

  1. 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']);
  2. Load slrt_ex_inport_square.mat, and then assign square to a temporary workspace variable.

    load('slrt_ex_inport_square.mat');
    waveform = square;
  3. Open slrt_ex_osc_inport/In1

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

  4. Turn off inport data interpolation.

    set_param(inport,'Interpolate','off');
  5. Set the external input variable.

    set_param(model,'ExternalInput','waveform');
  6. Load external input data.

    set_param(model,'LoadExternalInput','on');
  7. You can now build, download, and execute the real-time application.

    slbuild(model);
    tg = slrealtime('TargetPC1');
    load(tg,model);
    start(tg);
  8. 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.

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

    load(('slrt_ex_inport_sawtooth.mat');
    waveform = sawtooth;
  2. Create an application object.

    app_object = slrealtime.Application('slrt_ex_osc_inport');
  3. Update the application object.

    updateRootLevelInportData(app_object);
  4. Download the updated object to the target computer and execute it.

    tg = slrealtime;
    load(tg, 'slrt_ex_osc_inport');
    start(tg);
  5. View the signals in the Simulation Data Inspector.

    Simulink.sdi.view;

See Also

|

Related Topics