How to retrieve Source block Name of a Function block

1 view (last 30 days)
Hi everyone !
I have a simple model with a constant block connected to a function block connected to an output. Constant block can take True or False. And so i would like in the function block to color the Constant block according to the value (Green when True and Red when False).
To do that i could just use set_param with the name of the constant block but i have to do the solution using the source block of the function block.
I already tried this :
function y = fcn(u)
%#codegen
coder.extrinsic('set_param','get_param', 'gcb');
y = u;
b = struct('Type', {}, 'Position', {}, 'SrcBlock', {}, ...
'SrcPort', {}, 'DstBlock', {}, 'DstPort', {});
b = get_param(gcb ,'PortConnectivity');
s = b(1).SrcBlock;
if u == true
set_param(s ,'BackgroundColor','red');
else
set_param(s ,'BackgroundColor','green');
end
I had to create the struct of b because ifnot i had the error
Attempt to extract field 'SrcBlock' from 'mxArray'.
And now i have this error
Index expression out of bounds. Attempted to access element 1. The valid range is 1-0.
and i don't understand it.
Thanks you !

Answers (0)

Community Treasure Hunt

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

Start Hunting!