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
0 个评论
回答(1 个)
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 General Applications 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!