Attempting to find all blocks in a subsystem that conform to external criteria.

조회 수: 3 (최근 30일)
Brandon Emch
Brandon Emch 2022년 11월 11일
답변: SAI SRUJAN 2023년 10월 5일
I'm attempting to find all blocks in a simulink subsytem that have positions within bounds determined by another block's position. When I run the code below. I see this error:
Error using Simulink.findBlocks Option 'MatchFilter' must be a valid MATLAB function handle.
Code will run fine without the second input to 'below_current'.
Is there a way to use FindOptions and MatchFilter with a function using additional inputs?
blk_copy_pos = get_param(gcbh,'Position');
blk_hndls = Simulink.findBlocks(base_block,Simulink.FindOptions('MatchFilter', {@below_current,blk_copy_pos},'SearchDepth',1));
function match = below_current(blk,blk_copy_pos)
match = false;
blk_pos = get_param(blk,'Position');
if blk_pos(4) > blk_copy_pos(2) && blk_pos(3) >= blk_copy_pos(1) && blk_pos(1) <= blk_copy_pos(3)
match = true;
end
end

답변 (1개)

SAI SRUJAN
SAI SRUJAN 2023년 10월 5일
Hi Brandon Emch,
I understand that you are attempting to find all the blocks in a simulink subsystem that have positions within the bounds determined by another block's position.However you are facing an issue with Simulink.findBlocks and 'MatchFilter' option.
I can see that you are trying to pass arguments to the function handle as a Value pair to the option 'MatchFilter',which is leading to an error.The following code is an example on how to pass the arguments to the function.
myVariable=2;
function myFunction()
% Access a variable from the base workspace
myVariable = evalin('base', 'myVariable');
% Use the variable in your function
disp(myVariable);
end
You can use the evalin function to solve the problem that you are facing.For further insights, I have provided links to relevant documentation.

카테고리

Help CenterFile Exchange에서 General Applications에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by