Simulink.findBlocks error The first input must be a system name or handle.

8 次查看(过去 30 天)
Greetings,
Setup: create a model with a constant block in it.
Select the constant block
Type the following command:
Simulink.findBlocks(gcbh,'BlockType','Constant')
and get the error
Error using Simulink.findBlocks
The first input must be a system name or handle.
Caused by:
Error using Simulink.findBlocks
The first input is an object of type 'Constant block'.
This seems to apply to all native (unmasked) simulink library blocks which normally wouldn't be a problem but I have a masked block ('Mask' is 'On' but there is no masked subsystem, just some custom parameters) which returns the same error. Is there a particular parameter I can examine to sort this out?
Setting aside the inconsistent behavior of this function to emphasize my question, is there a block parameter that I can use to differentiate between a masked block with no subsystem and a masked block with a subsystem?
Thanks
-Chris
  2 个评论
Les Beckham
Les Beckham 2023-8-11
I don't understand why you are trying to "find" the current block (gcbh is a handle to the currently selected block).
Simulink.findBlocks is for searching in a model (system) to find blocks of a specified type. The error message is pretty clear about this.
What are you really trying to do?
checker
checker 2023-8-12
I use this to search thru masked blocks to find blocks of interest under the mask and it does that just fine for all but native simulink blocks and a masked blocks that have custom parameters only (no masked subsystem). The function accepts a handle and gcbh returns a handle. The error in this case is far from clear in that it says gcbh is object of type 'Constant block'! It's type is double and it's a handle to the block, hence my question. A consistent behavior would be to return an empty array with no error. I can achieve my goal by using find_system but that's an older function and I like the prototype of Simulink.findBlocks better.

请先登录,再进行评论。

回答(1 个)

C B
C B 2023-8-12
As it shows
Error using Simulink.findBlocks
The first input must be a system (name or handle).
So it is basically asking for system name or handle which should be model name or subsystem.
To solve this instead of selecting constant block.
Select the SubSystem
And Enter your command
Simulink.findBlocks(gcbh,'BlockType','Constant')
Please let me know if this is not what you want.
  1 个评论
checker
checker 2023-8-12
Thanks for the response. I don't see anywhere in the docs that translates 'name or handle' into 'model name or subsystem'. Obviously I'm using this command in a larger script that parses models for certain information so selecting a subsystem simply isn't an option. See my response to the other question for additional detail.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Subsystems 的更多信息

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by