Function block works in 2017b but not in 2019b

Hello,
I have created a Simulink model that allow the user to simulate some Constant (True = not OK / False = OK), and spread the information to upper block.
To do that i have a function block (Function Matlab) that change the color of the upper block (Function A block) according to the information he receive :
function y = fcn(u)
coder.extrinsic('set_param','get_param','gcs');
parent = get_param(gcs,'parent');
y = u;
if u == 3
set_param(parent,'BackgroundColor','red');
elseif u == 2
set_param(parent,'BackgroundColor','orange');
elseif u == 1
set_param(parent,'BackgroundColor','gray');
else
set_param(parent,'BackgroundColor','green');
end
So if he receive 3 the Block "Function A" goes red, 2 => Orange, 1=> Gray and if all is good => Green.
In my 2017b Matlab all is working well, but when i test my model in 2019b Matlab the uppers Block colors don't change as if the Function Block don't work in 2019b.
Do you know what changed between versions ?
Thanks for helping in advance.
PS : I attached the example model : Simulate.slx

2 Kommentare

Can you post the model file?
Lucas S
Lucas S am 7 Mär. 2022
I attached the example model file to the post !

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Fangjun Jiang
Fangjun Jiang am 21 Mär. 2022

0 Stimmen

Put a breakpoint in the code above and debug, the problem is clear.
The "parent" of your "gcs" is the root level model, which can't be assigned a background color.
Avoid using "gcs". Specify full path.

3 Kommentare

Lucas S
Lucas S am 21 Mär. 2022
Bearbeitet: Lucas S am 21 Mär. 2022
Is it a change from Matlab ? Because this code is perfectly working on 2017b. The "parent" of my "gcs" is always the upper block no matter which level of depth we are on.
I can't specify full path because this block is a generic block which is used many times in my model.
Indeed it is caused by the difference between R2017b and R2019b.
Paused after the "parent" line, gcb and gcs returned different value between R2017b and R2019b. In R2017b, there seems to have a S-function involved.
Lucas S
Lucas S am 21 Mär. 2022
Ok thanks you for your response ! I will try to solve this when i will have my 2019b version.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Simulink finden Sie in Hilfe-Center und File Exchange

Produkte

Version

R2017b

Gefragt:

am 2 Mär. 2022

Kommentiert:

am 21 Mär. 2022

Community Treasure Hunt

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

Start Hunting!

Translated by