Editing mask so that subsystem's color changes as per input port value

I would like change the color of my subsystem using the value come in the input port. See screenshot below, the subsystem is CB and the input port reads in a signal called "S1P1". I want CB to change its color as per the value of S1P1. Thanks

3 Comments

found a solution.
b = get_param(gcb,'PortHandles');
in = b.Inport(1);
line = get_param(in,'Line');
if line ~= -1
srcBlock = get_param(line,'SrcBlockHandle');
srcValue = get_param(srcBlock,'Value');
inputVal = evalin('base',srcValue);
if inputVal == 0
patch([0 1 1 0],[0 0 1 1],[1 0 0]);
end
if inputVal == 1
patch([0 1 1 0],[0 0 1 1],[0.5 0.5 0.5]);
end
end
Looks like a clever solution, except I'm wondering why this line
inputVal = evalin('base',srcValue);
isn't just
inputVal = srcValue;
Or just get rid of that line and use srcValue in the following if conditions.
Also, where did you put this code? In one of the model callbacks?
Hi Les,
here is additional explanation:
srcBlock = get_param(line,'SrcBlockHandle') % gets the handle
srcValue = get_param(srcBlock,'Value') % gets the signal name i.e. srcValue = 'SIP1' (see picture above)
inputVal = evalin('base',srcValue) % gets S1P1 value, i.e. inputVal = 1 (in this case)
the block that change color receives a signal at its input. This signal is given in the form of a parameter name (S1P1) which in turn is provided from a *.m file as I have many blocks for my project and I want to initialise those input signals (parameters) at once.
Also, The code is placed in "Icon" tap of the Edit MASK enviroment

Sign in to comment.

Answers (0)

Products

Release

R2024a

Asked:

on 18 Mar 2025

Edited:

on 21 Mar 2025

Community Treasure Hunt

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

Start Hunting!