Contenido principal

Generate MATLAB Scripts from Polyspace User Interface

You can specify analysis options in the Polyspace® Platform user interface and later generate a MATLAB® script to easily reuse those options.

The user interface provides tooltips, function name autocompletion, context-sensitive help, and other features to help you select the appropriate options. Once you have specified the options, you can generate a MATLAB script. For future analyses, you can modify and run this script without reopening the Polyspace user interface.

Prerequisites

Before you run Polyspace from MATLAB, you must link your Polyspace and MATLAB installations. See Integrate Polyspace with MATLAB and Simulink.

Example Files

This example uses a demo project provided with a Polyspace installation. Inspect the project in the Polyspace Platform user interface:

  1. To open the project, on the toolstrip, select Help > Examples > Prove absence of C runtime errors.

  2. Open the project configuration and note some of the options so that you can compare them later with generated MATLAB scripts. For instance, note that the option Compilation toolchain (Static analysis) is set to gnu13.x.

    A snapshot of a Polyspace configuration showing the Target & Compiler section.

Create Scripts from Polyspace Project

To generate MATLAB scripts from the sample project:

  1. Open MATLAB.

  2. Create a polyspace.Options object from the sample Polyspace project.

    projectFile = fullfile(polyspaceroot, 'polyspace', 'examples', 'cxx', ...
             'Code_Prover_Example', 'Code_Prover_Example.psprj');
    opts = polyspace.loadProject(projectFile);

    You cannot use the loadProject method on a project file that is created from a build command by using polyspace-configure.

  3. Append the object to a MATLAB script.

    filePath = opts.toScript('runPolyspace.m','append');

    Open the script runPolyspace.m and look for the option values that you previously noted in the user interface. For instance, you see the compilation toolchain for static analysis:

    opts.TargetCompiler.Compiler='gnu13.x';

    Later, you can run the script to recreate the polyspace.Options object and continue analysis in MATLAB.

    run(filePath);
    For more information on running analysis in MATLAB using a polyspace.Options object, see polyspace.Options.

See Also

Topics