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

4 次查看(过去 30 天)
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