Get Simulink Block Object
22 次查看(过去 30 天)
显示 更早的评论
Hello,
I switched from Matlab 2020 to 2022 and now I encounter the following issue:
I need to get direct access to the objects of all blocks in a Simulink model. This way I do not need to use "get_param" for each
property of the block handle.
In 2020 it worked this way (getting all block paths, then all handle IDs of all blocks and finally calling 'handle' delivered the object):
blockList = find_system(modelName, 'RegExp', 'on'); % list of all block paths in Simulink model
handlesList = get_param(blockList,'handle'); % list of handle IDs
>> handle(handlesList{7})
ans =
Simulink.Constant
The 'handle' call in Matlab 2022 does not return the object, anymore:
>> handle(handlesList{7})
ans =
handle
In both versions, directly getting the parameter 'object' from the list of block paths works, but that does not seem to be a valid parameter - at least it's not documented:
>> objectList = get_param(blockList,'object');
>> objectList{7}
ans =
Constant with properties:
Name: 'Constant'
Is there another ('official') way of getting hands on all objects of Simulink blocks inside a model?
Thanks a lot
TD
3 个评论
Paul
2022-6-28
You got the question. I was unaware of that method to access the handle that way and modify block properties.
I'm surprised that set_param and get_param are remarkably slower.
回答(1 个)
Pravarthana P
2022-6-30
Hi Timo Dietz,
I can understand that you are trying to get the objects of blocks used in Simulink through “handle” function. From R2022a version we have updated the objects of Simulink which is different from the “handle” function API used in the previous versions of Simulink, so usage of “handle” not returning block objects is an expected behavior in R2022a.
We are working on the documentation regarding the new API and the function to get the block objects directly may be available in future releases.
The suggested workaround will be to use “get_param()” to get the block objects. Kindly refer to the following documentation for further details: Get parameter names and values - MATLAB get_param (mathworks.com)
Hope this information helps you!!
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Model, Block, and Port Callbacks 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!