Main Content

compare

Compare the parameters in two parameter set objects

Since R2023b

Description

example

compResult = compare(paramSet1,paramSet2) compares two ParameterSet objects and returns a struct array that provides comparison information. The comparison contains parameter information, such as block path, parameter name, data type, and size, and it shows the different values saved in the ParameterSet objects.

Examples

collapse all

Use the compare function to compare two ParameterSet objects. For an example that shows how to use the output structure, see Resolve Parameter Set Objects.

  1. Open the model slrt_ex_osc_output. Build the real-time application. Connect to the target computer. Load the real-time application.

    openExample('slrt_ex_osc_outport');
    mdlName = 'slrt_ex_osc_outport';
    slbuild(mdlName);
    tg = slrealtime('TargetPC1');
    connect(tg);
    load(tg,mdlName);
  2. Create a ParameterSet object from the original parameters in the slrt_ex_osc_outport model. View the original value of the Amplitude parameter.

    paramSetNameOrig = 'ParamSetOrig';
    saveParamSet(tg,paramSetNameOrig);
    ParamSetObjOrig = importParamSet(tg,paramSetNameOrig);
    getparam(tg,'slrt_ex_osc_outport/Signal Generator','Amplitude')
    ans =
    
         1
  3. Change the value of the Amplitude parameter. Create a ParameterSet object from the modified parameters in the slrt_ex_osc_outport model.

    setparam(tg,'slrt_ex_osc_outport/Signal Generator','Amplitude',2)
    paramSetNameMod = 'ParamSetMod';
    saveParamSet(tg,paramSetNameMod);
    ParamSetObjMod = importParamSet(tg,paramSetNameMod);
  4. Compare the parameter values in the ParameterSet objects. View the comparison result structure. Observe the difference between the original and modified Amplitude parameter values.

    compResultAmp = compare(ParamSetObjOrig,ParamSetObjMod)
    compResultAmp = 
    
      4×1 struct array with fields:
    
        BlockPath
        Name
        DataType
        Size
        ParamSetObjOrig
        ParamSetObjMod
        Type

    Compare the parameter values by using the comparison structure for parameter set objects.

Input Arguments

collapse all

The paramSet1 argument specifies the first ParameterSet object for the comparison.

Example: ParamSetObjOrig

The paramSet2 argument specifies the second ParameterSet object for the comparison.

Example: ParamSetObjMod

Output Arguments

collapse all

The compResult argument specifies an output structure name for the comparison results. The returned structure has these fields:

  • BlockPath — Parameter block path

  • Name — Parameter name

  • DataType — Parameter data type

  • Size — Parameter data size

  • PS1 name — Parameter set 1 name

  • PS2 name — Parameter set 2 name

  • Type — For a specific parameter, the Type field value can be "Modification" if the parameter set 1 and parameter set 2 have different values at this parameter, "Insertion" if the parameter exists in parameter set 2 but does not exist in parameter set 1), or "Deletion" if the parameter exists in parameter set1 but does not exist in parameter set 2.

Version History

Introduced in R2023b