MATLAB: Can I change the color of signals in a Signal Builder block using the SIGNALBUILDER command in Simulink 7.9 (R2012a)

buildercolorcommandlinesignalsignalbuildersimulink

I am using the SIGNALBUILDER function to create and modify signals in a Signal Builder block from the command line. I have found that the GUI-based approach provides more functionality than command-line.
One example is changing the color of a signal, which does not seem to be achievable with SIGNALBUILDER. Are there any ways to do this without using the GUI?

Best Answer

The ability to change a signal color with the SIGNALBUILDER function is not available in Simulink 7.9 (R2012a).
As a workaround, you may use built-in MATLAB handle graphics functions to manipulate the Signal Builder figure. To make this process easier, please close all other figures open in your MATLAB session and take the following steps.
1. Set hidden graphics handles to be visible, so that the Signal Builder figure can be found using the command line.
set(0,'showHiddenHandles','on')
2. The Signal Builder figure window can be found with this command:
hSig = get(0,'children')
3. Then, we must go one step deeper to find all the child graphics objects of the Signal Builder figure, as follows:
hChildren = get(hSig,'children')
There should be several elements returned here, which will correspond to all objects such as text, individual lines, and more.
4. Let us say we now want to change the color of Signal 2, which can be found in Group 2. The best way to change the color of a signal is to use the FINDOBJ command to find the text "Signal 2" in the figure.
hText = findobj(hChildren,'Type','text','String','Signal 2')
One caveat about this is that the appropriate Group tab (Group 2 in this case) must be selected as the active tab in order to do this. Switching between group tabs will change the graphics objects found with the command above.
5. Store the color of the text object found:
sigColor = get(hText,'Color')
6. Finally, search for all objects of this color and change them to another color (say, blue):
allObjects = findobj(hChildren,'color',sigColor)
set(allObjects,'color','b');
The color of Signal 2 will have changed to blue in the Signal Builder window after these steps.