MATLAB: In the Simulink Data Inspector, can I automatically make all signals within the same run have the same color

automatic;colordatainspectorprogrammaticallyrunsschemesignalssimulink

I am using the Simulink data inspector to plot signals from multiple runs. Ideally, instead of each signal being a different color, I would like all signals within the same run to have the same color. For example, all of my signals from run 1 will be red, all of my signals from run 2 will be blue, etc.
I can set this manually for each signal, but this is time-consuming. Is there anyway I can save or automate this coloring configuration so I don't have to manually change all the colors every time?

Best Answer

This process can be automated using MATLAB commands. An example that demonstrating how to do this, "ColoringExample.slx", is attached.
Before running this example, close all other models, and run the following command in the MATLAB command window:
>> Simulink.sdi.clear
This command will clear any stored data from the Data Inspector so that you start with a fresh window.
Then, run "ColoringExample". If you open the Data Inspector, you will notice your typical results of multi-colored signals within the run.
If you click back to your model, and press "Ctrl-D" to "update" the model, you will notice that the signals will all change to a single color automatically.
This is due to MATLAB code in the model's callbacks. To see this code, navigate to File > Model Properties > Model Properties, and then click on the "Callbacks" tab. The "InitFcn" part contains code that sets up a matrix of 10 colors, and then adjusts the signal's colors based on what run they are in. Note that the code in this example will work for up to 10 runs in your Data Inspector. If you have more than 10 runs, you will need to add more colors to the matrix. The code in the "InitFcn" is executed every time you run a model, as well as every time you press "Ctrl-D".
For more information about how these "Simulink.sdi" functions work, see the attached script "ColoringScript" that demonstrates how this process for first signal of the first run.
To implement this in your model, you can add all the code included in the "InitFcn" to your model. If you are facing any issues or errors, first clear the data inspector using the "Simulink.sdi.clear" command, and then try again. Also, if you do not want to use model callbacks, you can put this code into a MATLAB script and run the script whenever you would like to automatically fix the colors.