How can I set up an automatically background color to blocks in Simulink?

Hi! I am an Automotive Engineering student and I am wondering if it is possible to let Simulink automatically use certain background colors for blocks?
I have been reading multiple "solutions" for this, for example this one:
It works but it works partly, since it doesn't work for me for inputs, subsystems, 1D look up tables. I have tried to work with the find_system and set_param statements but I don't really understand the find_system. I used the following code:
simulation_name;
Model='simulation_name';
Constant=find_system(Model,'FindAll','On','BlockType','Constant');
set(Constant,'BackgroundColor','green');
Subsystem=find_system(Model,'FindAll','On','BlockType','Subsystem');
set(Subsystem,'BackgroundColor','yellow');
And I tried to switch between all sorts of blocks but nothing I tried worked. So then I was wondering if it is possible to acces the library with the preferences where you could change the font, text size and maybe also color? If anyone has an other idea I would love to hear it as I am a bit tired of putting in every color manually.
Best regards,
Mike

6 Comments

The code should work. Did you try the example using f14 model referenced in that answer?
Yes, first I tried it like this with the f14 model:
%%load the example f14 model
f14;
Model='f14';
GainBlks=find_system(Model,'FindAll','On','LookUnderMasks', 'All','BlockType','Gain');
set(GainBlks,'BackgroundColor','red');
SumBlks=find_system(Model,'FindAll','On','LookUnderMasks', 'All','BlockType','Sum');
set(SumBlks,'BackgroundColor','yellow');
Just to test it if it would work. When this worked I tried to adjust the subsystem and input like this:
InputBlks=find_system(Model,'FindAll','On','LookUnderMasks', 'All','BlockType','Input');
set(InputBlks,'BackgroundColor','green');
subsystemBlks=find_system(Model,'FindAll','On','LookUnderMasks', 'All','BlockType','Subsystem');
set(subsystemBlks,'BackgroundColor','blue');
But this does not work, and I really don't know why because it is a copy/paste and the only difference is the color. Which I also changed to see if it might have been the color
The BlockType should be 'Inport', not 'Input'
should be 'SubSystem', not 'Subsystem'
Check the return variable of find_system() to see if it finds the blocks
Awesome! This works perfectly! So to check the necessary block type I have to use the find_system() also for like a look up table? As in, how did you know that it had to be SubSystem and Inport?
Do it manually first. Select a block in the model, run "get(gcbh,'BlockType')" in MATLAB.
Thank you very much for your help! I can get it working from here! Awesome

Sign in to comment.

Answers (0)

Categories

Products

Release

R2021b

Asked:

on 2 Mar 2022

Commented:

on 2 Mar 2022

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!