Effacer les filtres
Effacer les filtres

Get Simulink Block Object

24 vues (au cours des 30 derniers jours)
Timo Dietz
Timo Dietz le 27 Juin 2022
Modifié(e) : Timo Dietz le 4 Juil 2022
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 =
The 'handle' call in Matlab 2022 does not return the object, anymore:
>> handle(handlesList{7})
ans =
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
  3 commentaires
Timo Dietz
Timo Dietz le 28 Juin 2022
Modifié(e) : Timo Dietz le 28 Juin 2022
Not sure whether I got your question.
I'm using the returned instance for a lot of things: retrieving information, manipulating the Simulink block.
Actually, I'm reading/writing several properties like 'BackgroundColor', 'Position', 'Mask', etc. .
I know, 'get_param' and 'set_param' would work too, but for some reason these operations are remarkably slower
(at least this was the case as I started with the project some years ago with Matlab 2018).
Paul le 28 Juin 2022
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.

Connectez-vous pour commenter.

Réponses (1)

Pravarthana P
Pravarthana P le 30 Juin 2022
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!!
  1 commentaire
Timo Dietz
Timo Dietz le 1 Juil 2022
Modifié(e) : Timo Dietz le 4 Juil 2022
Thanks for the reply.
Can you tell me whether the parameter 'object' will be valid also in future releases? Currently, it does not seem to be documented being a 'get_param()' parameter.
Sure, I could change the code and get the object by 'get_param(handle, 'object')' but it would be great to know whether that's only a workaround or a long-term solution.
Many thanks in advance,

Connectez-vous pour commenter.


En savoir plus sur Simulink Functions dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by