How to retrieve Source block Name of a Function block
조회 수: 1 (최근 30일)
이전 댓글 표시
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 !
댓글 수: 0
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Event Functions에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!