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

조회 수: 6 (최근 30일)
checker
checker 2023년 8월 11일
편집: checker 2023년 8월 12일
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