Define and Update Inport Data with 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.

File Dependencies

This procedure depends on the following files:

Before starting this procedure, navigate to a working folder.

Map Inport to Use Square Wave

  1. Open ex_slrt_inport_osc.

    model = docpath(fullfile(docroot, 'toolbox', 'xpc', 'examples',...
        'ex_slrt_inport_osc'));
    open_system(model);
    save_system(model,'H:\workdir\ex_slrt_inport_osc.slx');
  2. Load ex_slrt_inport_square.mat, and then assign square to a temporary workspace variable.

    load(docpath(fullfile(docroot, 'toolbox', 'xpc', 'examples', ...
        'ex_slrt_inport_square.mat')));
    waveform = square;
  3. Open ex_slrt_inport_osc/In1

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

  4. Turn off inport data interpolation.

    set_param(inport,'Interpolate','off');
  5. Set 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.

    rtwbuild(model);
    tg = slrt('TargetPC1');
    load(tg,model);
    start(tg);
  8. Plot the output.

    plot(tg.TimeLog,tg.OutputLog);

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 ex_slrt_inport_osc.mldatx file must be in the working folder.

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

    load(docpath(fullfile(docroot, 'toolbox', 'xpc', 'examples', ...
        'ex_slrt_inport_sawtooth.mat')));
    waveform = sawtooth;
  2. Create an application object.

    app_object = SimulinkRealTime.Application('ex_slrt_inport_osc');
  3. Update the application object.

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

    tg = slrt;
    load(tg, 'ex_slrt_inport_osc');
    start(tg);
  5. Plot the output.

    plot(tg.TimeLog,tg.OutputLog);

Related Topics