MATLAB: How to compare differences between two Simulink models

comparisonexportgeneratormodelreportsimulinktoxml

I have two versions of the same Simulink model, and I would like to automatically find the differences between them. How can I do this?

Best Answer

Since MATLAB R2017b, base Simulink comes with a Model Comparison feature, which will allow you to see a comparison of differences between two Simulink models. With the Comparison Tool, you can review as well as merge differences. You can use models from any version of Simulink. Use the Comparison Tool to explore the differences, view the changes highlighted in the original models, and merge differences. See the following documentation page for further information, as well as multiple examples on how to use Simulink Model Comparison:
There are three basic ways to initiate the comparison:
  1. Select two Simulink models at once (e.g. by holding down the CTRL key while selecting one file after another in the “Current Folder” pane of MATLAB) and right click on the selection. In the appeared menu, select “Compare Selected Files/Folders”.
  2. Alternatively, you may select one of the Simulink models, right click and select “Compare Against” > “Choose…”, then select the second Simulink model from the file browser in the “Selecting Files or Folders for Comparison” dialog box.
  3. Click on the “compare” button in the MATLAB tool-strip under the “File” section. In the “Selecting Files or Folders for Comparison” dialog box, use the file browser to select the two Simulink model files for comparison.
Note that for MATLAB R2017a and earlier, doing this kind of comparison requires to have "Simulink Report Generator" toolbox installed and licensed for. For more information about comparing Simulink Models using Simulink Report Generator, and navigating through the Comparison Report, please refer to the link below:
Unfortunately, there is no practical way to compare two Simulink models without using the Simulink Report Generator toolbox in R2017a and earlier. Without the toolbox, there is a workaround in which you may export the models first into XML files via the “save_system” function. The command to use has the following syntax:
>> save_system('model_name’, 'model_xml.xml','ExportToXML', true);
Then use any commercial software available to compare the two XML files. This is not recommended as small changes in your model could result in large changes in the XML file, and thus raw comparison could yield misleading results.