Matlab Simulink without matlab function access

조회 수: 5 (최근 30일)
Bruno Peixoto
Bruno Peixoto 2021년 2월 8일
답변: Rajanya 2025년 1월 30일
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

답변 (1개)

Rajanya
Rajanya 2025년 1월 30일
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!

카테고리

Help CenterFile Exchange에서 Programmatic Model Editing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by