Matlab Simulink without matlab function access

4 visualizzazioni (ultimi 30 giorni)
Bruno Peixoto
Bruno Peixoto il 8 Feb 2021
Risposto: Rajanya il 30 Gen 2025
I try to alter the properties of a MatlabFunction on Simulink. The recommended commands are below.
open_system('my_model');
S = sfroot
B = S.find('Name','myBlockName','-isa','Stateflow.EMChart');
The 'BlockName' is a MatlabFunction on the model 'my_model'. The content of B is '0×1 empty handle' and S.Name gives 'DefaultBlockDiagram'. It seems it does not recognize the opened model. Could you help me somehow?
Best regards, Bruno Peixoto

Risposte (1)

Rajanya
Rajanya il 30 Gen 2025
I recommend to double check the name of the MATLAB function block before executing the 'find' function using:
blockPath = find_system('my_model')
Sometimes, in versions earlier than R2020a, pressing 'Enter' after typing the name of a block actually adds a newline character to the name of the block, or there might also be spaces after the name for which the 'find' function might fail to find the block.
A safer way to do the same thing would be to use 'get_param' with block handles. For example, consider a demo model 'model2' containing the following:
%blockPath = 4×1 cell array
%{'model2' }
%{'model2/Constant' }
%{'model2/Display' }
%{'model2/myBlockName'}
We can get the handle to the desired block and use 'find', instead of using it on 'sfroot'.
blockHandle = get_param(blockPath{4}, 'Handle'); %get blockPath using find_system
B = find(get_param(blockHandle, 'Object'), '-isa', 'Stateflow.EMChart');
This results in the expected 1x1 'EMChart' object to be stored in B.
Hope this would help. Thanks!

Categorie

Scopri di più su Programmatic Model Editing in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by