Documentation

Save and Reload Parameters with MATLAB Language

After you have a set of real-time application parameter values, save those values to a file on the target computer. You can then later reload these parameter values to the same real-time application.

You can save parameters from your real-time application while the real-time application is running or between runs. You can save and restore parameters in your real-time application without rebuilding the Simulink® model. Load parameters to the same model from which you save the parameter file. If you load a parameter file to a different model, the behavior is undefined.

You save and restore parameters with the target object methods saveparamset and loadparamset.

Requirements:

  • You have a real-time application object named tg.

  • You have assigned tg to the target computer.

  • You have downloaded a real-time application to the target computer.

  • You have parameters to save.

Save the Current Set of Real-Time Application Parameters

To save a set of parameters to a real-time application, use the saveparamset method. This example uses the model ex_slrt_outport_osc (matlab: open_system(docpath(fullfile(docroot, 'toolbox', 'xpc', 'examples', 'ex_slrt_outport_osc')))). The real-time application can be stopped or running.

  1. Identify the set of parameter values that you want to save.

  2. Select a descriptive file name for the parameters. For example, use the model name in the file name.

  3. In the Command Window, type:

    tg = slrt;
    saveparamset(tg, 'ex_slrt_outport_osc_param1')

    The Simulink Real-Time™ software creates a file named ex_slrt_outport_osc_param1 in the current folder of the target computer, for example, C:\ex_slrt_outport_osc_param1.

Load Saved Parameters to a Real-Time Application

To load a set of saved parameters to a real-time application, use the loadparamset method.

Load parameters to the same model from which you save the parameter file. If you load a parameter file to a different model, the behavior is undefined. This example uses the model ex_slrt_outport_osc (matlab: open_system(docpath(fullfile(docroot, 'toolbox', 'xpc', 'examples', 'ex_slrt_outport_osc')))).

This section assumes that you have a parameters file saved from an earlier run of saveparamset (see Save the Current Set of Real-Time Application Parameters).

  1. From the collection of parameter value files on the target computer, select the one that contains the parameter values you want to load.

  2. In the Command Window, type:

    tg = slrt;
    
    loadparamset(tg, 'ex_slrt_outport_osc_param1') 

    The Simulink Real-Time software loads the parameter values into the real-time application.

List the Values of Parameters Stored in a File

To list parameters and their values, load the file for a real-time application, and then turn on the ShowParameters target object property.

You must have a parameters file saved from an earlier run of saveparamset (see Save the Current Set of Real-Time Application Parameters).

  1. Stop the real-time application. In the Command Window, type:

    stop(tg)
  2. Load the parameter file. Type:

    tg = slrt;
    
    loadparamset(tg, 'ex_slrt_outport_osc_param1');
  3. Display a list of parameters. Type:

    tg.ShowParameters = 'on'

    The Command Window displays a list of parameters and their values for the target object.

More About

Was this topic helpful?