Main Content

generateScript

R2026b

Generate MATLAB script to create scope with current settings

Description

generateScript(scope) generates a MATLAB® script that can recreate a scope object with the current settings in the scope.

Examples

collapse all

  1. Create a spectrumAnalyzer object.

    scope = spectrumAnalyzer();
    show(scope);
  2. Set options in the Spectrum Analyzer. For this example, select both Spectrum and Spectrogram in the Home tab of the Spectrum Analyzer toolstrip.

    In addition, click the Spectrum drop-down arrow, and select the Max-Hold Trace and Min-Hold Trace parameters.

  3. Generate a script to recreate the spectrumAnalyzer with the modified settings. Either click Generate Script from the Export drop-down in the Home tab, or enter this command in the MATLAB command prompt.

    generateScript(scope);

    A new editor window opens with code to regenerate the same scope.

    % Generated by MATLAB(R) 26.2 (R2026b) and DSP System Toolbox 26.2 (R2026b).
    % Generated on 16-Mar-2026 17:24:04 -0400.
    
    % Construct a spectrumAnalyzer object
    specScope=spectrumAnalyzer(ViewType="spectrum-and-spectrogram", ...
        PlotMaxHoldTrace=true, ...
        PlotMinHoldTrace=true, ...
        Position=[282 150 800 500]);

  1. Create a dsp.ArrayPlot object.

    scope = dsp.ArrayPlot();
    show(scope);
  2. Set options in the Array Plot. For this example, from the Measurements tab, turn on the Data Cursors. From the Scope tab, turn on Legend. Click Settings. Select Magnitude Phase Plot, and specify an x-axis label and a title.

    Array Plot scope configured with Magnitude Phase Plot, title My Array Plot, x-axis label Frequency, and two subplots showing Magnitude and Phase

  3. Generate a script to recreate the dsp.ArrayPlot with the same modified settings. Either select Generate Script from the Scope tab, or enter the following in the MATLAB command prompt:

    generateScript(scope);

    A new editor window opens with code to regenerate the same scope.

    % Generated by MATLAB(R) 24.2 (R2024b) and DSP System Toolbox 24.2 (R2024b).
    % Generated on 24-Apr-2024 14:37:28 -0400.
    
    % Construct a dsp.ArrayPlot object
    arrayPlot=dsp.ArrayPlot(AxesScaling="Manual", ...
        Position=[2260 393 800 500], ...
        PlotAsMagnitudePhase=true, ...
        Title="My Array Plot", ...
        XLabel="Frequency", ...
        ShowLegend=true);
    % Cursor Measurements Configuration
    arrayPlot.CursorMeasurements.Enabled=true;
    

  1. Create a timescope object.

    scope = timescope;
    show(scope)
  2. Set options in the Time Scope. For this example, on the Scope tab, click Settings. Under Display and Labels, select Show Legend and Magnitude Phase Plot. Set the Title as well.

    Time Scope configured with Magnitude Phase Plot, title My Time Scope, and two subplots showing Magnitude and Phase versus Time (secs)

  3. Generate a script to recreate the timescope with the same modified settings. Either select Generate Script from the Scope tab, or enter the following in the MATLAB command prompt:

    generateScript(scope);

    A new editor window opens with code to regenerate the same scope.

    % Generated by MATLAB(R) 26.2 (R2026b) and DSP System Toolbox 26.2 (R2026b).
    % Generated on 18-Jun-2026 14:47:07 -0400.
    
    % Construct a timescope object
    timeScope=timescope(Position=[2224 151 800 500], ...
        PlotAsMagnitudePhase=true, ...
        Title="My Time Scope", ...
        ShowLegend=true);
    

Input Arguments

collapse all

Scope object whose settings you want to recreate with a script, specified as one of the following:

  • spectrumAnalyzer object

  • dsp.ArrayPlot object

  • timescope object

  • dsp.DynamicFilterVisualizer object

Version History

Introduced in R2019a

expand all