Programmatically Analyze and Upgrade Model
This example shows how to analyze and upgrade your model, and then apply automatic fixes when they are available.
1. Load your model and create an upgrader
object. In this example, to load and open the example model, open the project that contains the model.
openProject("ModelReferenceHierarchy"); upgrader = upgradeadvisor("sldemo_mdlref_depgraph.slx")
upgrader = Upgrader with properties: ChecksToSkip: {} SkipLibraries: 0 SkipBlocksets: 1 OneLevelOnly: 0 ShowReport: 1 VerboseLogging: 0 RootModel: 'sldemo_mdlref_depgraph' ReportFile: '' Run "upgrade" on this Upgrader object to analyze and automatically upgrade your models.
2. Analyze the model for recommended upgrades, following library links and model references.
analyze(upgrader);
(1/14) Analyzing Model "sldemo_mdlref_depgraph" (2/14) Analyzing Model "sldemo_mdlref_heat2cost" (3/14) Analyzing Model "sldemo_mdlref_house" (4/14) Analyzing Model "sldemo_mdlref_F2C" (5/14) Analyzing Model "sldemo_mdlref_outdoor_temp" (6/14) Analyzing Model "sldemo_mdlref_thermostat" (7/14) Analyzing Model "sldemo_mdlref_heater" (8/14) Analyzing Model "sldemo_mdlref_heat2cost" using compile time information (9/14) Analyzing Model "sldemo_mdlref_house" using compile time information (10/14) Analyzing Model "sldemo_mdlref_F2C" using compile time information (11/14) Analyzing Model "sldemo_mdlref_outdoor_temp" using compile time information ### Starting serial model reference simulation build. ### Model reference simulation target for sldemo_mdlref_F2C is up to date. Build Summary 0 of 1 models built (1 models already up to date) Build duration: 0h 0m 2.1551s ### Starting serial model reference code generation build. ### Checking status of model reference code generation target for model 'sldemo_mdlref_F2C' used in 'sldemo_mdlref_outdoor_temp'. ### Checking for structural changes in sldemo_mdlref_F2C because the model reference rebuild option is set to 'If any changes detected'. Structural changes cause the model reference code generation target to be rebuilt. ### Checking for structural changes in model reference code generation target for: sldemo_mdlref_F2C ### Generating code and artifacts to 'Model specific' folder structure ### Code for the model reference code generation target for model sldemo_mdlref_F2C is up to date because no functional changes were found in referenced model. ### Model reference code generation target for sldemo_mdlref_F2C is up to date. Build Summary 0 of 1 models built (1 models already up to date) Build duration: 0h 0m 1.3025s ### Starting serial model reference simulation build. ### Model reference simulation target for sldemo_mdlref_F2C is up to date. Build Summary 0 of 1 models built (1 models already up to date) Build duration: 0h 0m 1.4746s (12/14) Analyzing Model "sldemo_mdlref_thermostat" using compile time information (13/14) Analyzing Model "sldemo_mdlref_heater" using compile time information ### Starting serial model reference simulation build. ### Model reference simulation target for sldemo_mdlref_thermostat is up to date. Build Summary 0 of 1 models built (1 models already up to date) Build duration: 0h 0m 1.4151s ### Starting serial model reference code generation build. ### Checking status of model reference code generation target for model 'sldemo_mdlref_F2C' used in 'sldemo_mdlref_heater'. ### Checking for structural changes in sldemo_mdlref_F2C because the model reference rebuild option is set to 'If any changes detected'. Structural changes cause the model reference code generation target to be rebuilt. ### Checking for structural changes in model reference code generation target for: sldemo_mdlref_F2C ### Generating code and artifacts to 'Model specific' folder structure ### Code for the model reference code generation target for model sldemo_mdlref_F2C is up to date because no functional changes were found in referenced model. ### Model reference code generation target for sldemo_mdlref_F2C is up to date. ### Checking status of model reference code generation target for model 'sldemo_mdlref_thermostat' used in 'sldemo_mdlref_heater'. ### Checking for structural changes in sldemo_mdlref_thermostat because the model reference rebuild option is set to 'If any changes detected'. Structural changes cause the model reference code generation target to be rebuilt. ### Checking for structural changes in model reference code generation target for: sldemo_mdlref_thermostat ### Generating code and artifacts to 'Model specific' folder structure ### Code for the model reference code generation target for model sldemo_mdlref_thermostat is up to date because no functional changes were found in referenced model. ### Model reference code generation target for sldemo_mdlref_thermostat is up to date. Build Summary 0 of 2 models built (2 models already up to date) Build duration: 0h 0m 2.0631s ### Starting serial model reference simulation build. ### Model reference simulation target for sldemo_mdlref_thermostat is up to date. Build Summary 0 of 1 models built (1 models already up to date) Build duration: 0h 0m 1.5653s (14/14) Analyzing Model "sldemo_mdlref_depgraph" using compile time information ### Starting serial model reference simulation build. ### Model reference simulation target for sldemo_mdlref_F2C is up to date. ### Model reference simulation target for sldemo_mdlref_thermostat is up to date. ### Model reference simulation target for sldemo_mdlref_heat2cost is up to date. ### Model reference simulation target for sldemo_mdlref_house is up to date. ### Model reference simulation target for sldemo_mdlref_outdoor_temp is up to date. Build Summary 0 of 5 models built (5 models already up to date) Build duration: 0h 0m 0.7038s ### Starting serial model reference code generation build. ### Checking status of model reference code generation target for model 'sldemo_mdlref_F2C' used in 'sldemo_mdlref_depgraph:sldemo_mdlref_heater'. ### Model reference code generation target for sldemo_mdlref_F2C is up to date. ### Checking status of model reference code generation target for model 'sldemo_mdlref_thermostat' used in 'sldemo_mdlref_depgraph:sldemo_mdlref_heater'. ### Model reference code generation target for sldemo_mdlref_thermostat is up to date. ### Checking status of model reference code generation target for model 'sldemo_mdlref_heat2cost' used in 'sldemo_mdlref_depgraph'. ### Model reference code generation target for sldemo_mdlref_heat2cost is up to date. ### Checking status of model reference code generation target for model 'sldemo_mdlref_house' used in 'sldemo_mdlref_depgraph'. ### Model reference code generation target for sldemo_mdlref_house is up to date. ### Checking status of model reference code generation target for model 'sldemo_mdlref_heater' used in 'sldemo_mdlref_depgraph'. ### Model reference code generation target for sldemo_mdlref_heater is up to date. ### Checking status of model reference code generation target for model 'sldemo_mdlref_outdoor_temp' used in 'sldemo_mdlref_depgraph'. ### Model reference code generation target for sldemo_mdlref_outdoor_temp is up to date. Build Summary 0 of 6 models built (6 models already up to date) Build duration: 0h 0m 0.77985s ### Starting serial model reference simulation build. ### Model reference simulation target for sldemo_mdlref_F2C is up to date. ### Model reference simulation target for sldemo_mdlref_thermostat is up to date. ### Model reference simulation target for sldemo_mdlref_heat2cost is up to date. ### Model reference simulation target for sldemo_mdlref_house is up to date. ### Model reference simulation target for sldemo_mdlref_outdoor_temp is up to date. Build Summary 0 of 5 models built (5 models already up to date) Build duration: 0h 0m 0.68423s
3. Specify an output to find the location of the report.
reportLocation = upgrader.ReportFile;
4. Configure options before you analyze or upgrade your model.
By default,
upgradeadvisor
generates backup copies for models during the upgrade process. To turn off the generation of backup files, set theEnableBackups
property.
upgrader.EnableBackups = false;
To skip a check, in the Upgrade Advisor, right-click the check, select Send Check ID to Workspace, and set the
ChecksToSkip
property.
upgrader.ChecksToSkip = {"mathworks.design.CSStoVSSConvert"};
To analyze or upgrade the current model without analyzing library links, model references, or test harnesses that are saved as external models, enable the
OneLevelOnly
property.
upgrader.OneLevelOnly = true;
To analyze or upgrade the current model and model references but not library links, enable the
SkipLibraries
property.
upgrader.SkipLibraries = true;
To analyze and upgrade the current models and files in blocksets or toolboxes, disable the
SkipBlocksets
property. By default, the Upgrade Advisor does not upgrade files in blocksets or toolboxes. The Upgrade Advisor detects blocksets from the output of thever
function and the existence of theContents
file.
upgrader.SkipBlocksets = false;
To turn off showing the report after you analyze or upgrade your model, disable the
ShowReport
property.
upgrader.ShowReport = false;
5. Upgrade the model and apply automatic fixes when they are available.
upgrade(upgrader);
(1/2) Upgrading Model "sldemo_mdlref_depgraph" (2/2) Upgrading Model "sldemo_mdlref_depgraph" using compile time information ### Starting serial model reference simulation build. ### Model reference simulation target for sldemo_mdlref_F2C is up to date. ### Model reference simulation target for sldemo_mdlref_thermostat is up to date. ### Model reference simulation target for sldemo_mdlref_heat2cost is up to date. ### Model reference simulation target for sldemo_mdlref_house is up to date. ### Model reference simulation target for sldemo_mdlref_outdoor_temp is up to date. Build Summary 0 of 5 models built (5 models already up to date) Build duration: 0h 0m 0.66955s ### Starting serial model reference code generation build. ### Checking status of model reference code generation target for model 'sldemo_mdlref_F2C' used in 'sldemo_mdlref_depgraph:sldemo_mdlref_heater'. ### Model reference code generation target for sldemo_mdlref_F2C is up to date. ### Checking status of model reference code generation target for model 'sldemo_mdlref_thermostat' used in 'sldemo_mdlref_depgraph:sldemo_mdlref_heater'. ### Model reference code generation target for sldemo_mdlref_thermostat is up to date. ### Checking status of model reference code generation target for model 'sldemo_mdlref_heat2cost' used in 'sldemo_mdlref_depgraph'. ### Model reference code generation target for sldemo_mdlref_heat2cost is up to date. ### Checking status of model reference code generation target for model 'sldemo_mdlref_house' used in 'sldemo_mdlref_depgraph'. ### Model reference code generation target for sldemo_mdlref_house is up to date. ### Checking status of model reference code generation target for model 'sldemo_mdlref_heater' used in 'sldemo_mdlref_depgraph'. ### Model reference code generation target for sldemo_mdlref_heater is up to date. ### Checking status of model reference code generation target for model 'sldemo_mdlref_outdoor_temp' used in 'sldemo_mdlref_depgraph'. ### Model reference code generation target for sldemo_mdlref_outdoor_temp is up to date. Build Summary 0 of 6 models built (6 models already up to date) Build duration: 0h 0m 0.67922s ### Starting serial model reference simulation build. ### Model reference simulation target for sldemo_mdlref_F2C is up to date. ### Model reference simulation target for sldemo_mdlref_thermostat is up to date. ### Model reference simulation target for sldemo_mdlref_heat2cost is up to date. ### Model reference simulation target for sldemo_mdlref_house is up to date. ### Model reference simulation target for sldemo_mdlref_outdoor_temp is up to date. Build Summary 0 of 5 models built (5 models already up to date) Build duration: 0h 0m 0.99939s
The Upgrade Advisor displays the list of found issues and automatic fixes.
The Upgrade Advisor saves fixes to the model files.