Note: DiffPlug does not require MATLAB. The tracking feature is purely optional, and MATLAB is not required to view or diff Simulink models.

In the top right of every Simulink dialog, there is a Track in MATLAB button. While the button is engaged, MATLAB will mirror the selections you make in DiffPlug. This is especially useful for resolving differences which were detected in a diff.

MATLAB tracking example

When you first press this button, you will have to establish a connection with a MATLAB instance.

Establish a connection.

A confirmation message will print at the MATLAB console when the connection has been established.

Confirm the connection.

It might take a few seconds for MATLAB to load your model, but the tracking will be almost instantaneous once it is established. The tracking will continue until you toggle the tracking button to off.

Now that you’re connected to MATLAB, DiffPlug will reuse this connection until either DiffPlug or MATLAB are closed. If you hover over the Track in MATLAB while tracking is active, you can open the Details of the MATLAB instance you are currently connected to.

Hover while tracking is active

MATLAB connection details

If you press the Click to flash MATLAB button, MATLAB’s console and editor windows will flash blue. This lets you know that the connection is working, and if you have several instances of MATLAB open it is helpful in quickly determining which instance you are controlling.

Connections are persistent, so you don’t have to connect every time. But if you want to disconnect (so that you can connect to a different intsance of MATLAB, for example), you can connect and disconnect as many times as you would like.

Limitations

MATLAB can’t open two models with the same name, even if they’re in different folders. The consequence of this is that you can usually only track one side of a diff at a time. This is rarely a practical limitation, as there is usually only one model which is being actively modified.

MATLAB can’t open a Simulink file if the filename is not a valid MATLAB identifier. Many version control systems mangle the name of files when exporting them to a temporary directory for viewing. If you attempt to track a Simulink file which has been mangled in this way, DiffPlug will find a similar name which is a valid MATLAB identifier, copy the Simulink model to a read-only temporary file with that name, and then open that temporary file.

There are some Simulink objects which cannot be highlighted using the MATLAB API. These objects include:

  • Wires between blocks.
  • Any element with a forward-slash (/) in its name.
  • Stateflow transitions which cross boxes.

Despite these limitations, the vast majority of elements are supported. If the object you click in DiffPlug doesn’t light up in MATLAB right away, try clicking one of the elements next to it - that will usually be enough to help you find what you’re looking for.