Port or Restore Model Changes in Comparison Report
In the comparison report, you can use merge mode to port changes between models on disk or restore changes between model revisions. If you have not yet run a comparison analysis, see Select Models to Compare.
The Merge Mode button in the Comparison Tool enables you to port or restore individual changes between Simulink® models using two-way merge. For example, you can restore individual parameters, blocks, or entire subsystems. For deleted and inserted subsystems, to ensure the integrity of the models, the Comparison Tool only allows you to restore the entire subsystem.
Tip
Merge blocks before lines, and merge states and junctions before merging transitions. See Recommended Merge Order in Models.
To port or restore changes in models:
In the Comparison toolstrip, click Merge Mode. The Comparison Tool expands the first change and opens a Target pane at the bottom of the report.
If you enabled Always Highlight, the Comparison Tool also opens a temporary model called
targetFile*
.Use the buttons in the row of the Target pane to select the differences you want to keep in the target file.
In this example report, suppose you want to restore the Value of the Constant block to the one in the Left model. In the Target pane, click the left button in the Value row.
Click Next to navigate to the next difference.
If your models contain MATLAB® Function blocks, the Comparison Tool enables you to port or restore changes in individual lines in MATLAB Function blocks code.
With merge mode enabled, in the comparison report of the parent models, in the
targetFile*
, use the buttons in the MATLAB Function block to select the line of codes you want to keep in the target file.In this example report, suppose you want to keep the description in the Right MATLAB Function block model. In the Target pane, click the right buttons in the MATLAB Function code rows.
When you finish porting or restoring changes, save your choices in the temporary
targetFile*
over the right model using the Save File button.If you want to cancel all operations instead, click Close Merge without saving the file.
Inspect your changes in the Simulink Editor. If necessary, connect any lines that the software did not connect automatically. The comparison report does not update to show any changes that you make in the editor.
Tip
If you are using source control outside of MATLAB, you can customize external source control tools to use MATLAB Comparison and Merge tools.
For instructions, see Customize External Source Control to Use MATLAB for Diff and Merge.
Recommended Merge Order in Models
In the Simulink part of the report, merge items in the models in this order. In the target file:
Delete the lines you do not want to keep.
Delete the blocks, states, and junctions you do not want to keep.
Add the blocks, states, and junctions you want to keep.
Add the lines you want to keep.
Select the parameters you want to keep.
For an example showing how to merge a change involving multiple nodes, see Compare and Merge Simulink Models Containing Stateflow.
Not all parameters can be merged. In this case, the Comparison Tool shows only one button in the target pane indicating the version that is in the target model.