Attempting to find all blocks in a subsystem that conform to external criteria.
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (1)
SAI SRUJAN
el 5 de Oct. de 2023
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 comentarios
Ver también
Categorías
Más información sobre General Applications en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!