Generate MATLAB Scripts from Polyspace User Interface
You can specify analysis options in the Polyspace® user interface and later generate a MATLAB® script for easier reuse of those options.
In the user interface, to determine which options to specify, you have tooltips, autocompletion of function names, context-sensitive help and so on. After you specify the options, you can generate a MATLAB script. For subsequent analyses, you can modify and run the script without opening 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.
Create Scripts from Polyspace Projects
To start an analysis in the Polyspace user interface, create a project. In the project:
You specify source and include folders during project creation.
You specify analysis options such as compiler or multitasking in your project configuration. You also enable or disable checkers.
From this project, you can generate a script that contains your sources, includes and other analysis options. To begin, select File > New Project. For details, see Add Source Files for Analysis in Polyspace User Interface.
This example uses a sample project. To open the project, select Help > Examples > Code_Prover_Example.psprj. You see the options in the project configuration. For instance, on
the Target & Compiler node, you see a
generic
compiler and an
i386
processor.
Open MATLAB.
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);
If a project has more than one module (with more than one configuration in each module), the options from the currently active configuration in the currently active module will be extracted in the options object. You cannot use the
loadProject
method on a project file that is created from a build command by usingpolyspace-configure
.Append the object to a MATLAB script.
filePath = opts.toScript('runPolyspace.m','append');
Open the script
runPolyspace.m
. You see the options that you specified from the user interface. For instance, you see the compiler and target processor.opts.TargetCompiler.Compiler = 'generic'; opts.TargetCompiler.Target = 'i386';
Later, you can run the script to create a
polyspace.Options
object.run(filePath);
The preceding example converts the sample project
Code_Prover_Example
directly to a script. When you open the
sample project in the user interface, a copy is loaded into your Polyspace workspace. If you make changes to the sample project, the changes are
made to the copied version. To see the changes in your MATLAB script, provide the copied project path to the
loadProject
method. To see the location of your workspace,
select Tools > Preferences and view the Project and Results Folder
tab.