How to find Matlab Function blocks in a model?

조회 수: 32 (최근 30일)
Hadi Zyien
Hadi Zyien 2019년 5월 30일
편집: Christophe Pouillot 2023년 11월 14일
I would like to use find_system to find all MATLAB Function blocks (from the User-Defined Functions library) in a model. The problem is that all MATLAB Function blocks are of BlockType SubSystem. What parameters can I use to only find the MATLAB Function blocks?

채택된 답변

Monika Jaskolka
Monika Jaskolka 2019년 6월 5일

추가 답변 (2개)

Murugan C
Murugan C 2019년 5월 31일
Hi Hadi Zyien
Yes, We have to use find_system to find matlab function block. After that, we need to use get_param command for finding matlab function block. Matlab Function block will have three to four parametes, as like
get_blocks ={' Demux ';' Ground ';' SFunction ';' Terminator '};
Use below code.
clc
clear
find_mat_fn = find_system(gcs,'BlockType','SubSystem'); % finding Subsytem
mat_fn = {' Demux ';'Ground';' SFunction ';' Terminator '}; % default parameter for Matlab Function Block
mat_blk_name = 1;
for i = 1 : length(find_mat_fn)
get_blocks = get_param(find_mat_fn{i}, 'Blocks'); % Blocks will returns what are the blocks used in subsystem
check_block = find(ismember(get_blocks,mat_fn) == 1); % comparing with default parameter
if check_block
matlab_fcn_blck{mat_blk_name} = find_mat_fn{i};
mat_blk_name = mat_blk_name + 1;
end
end
disp(matlab_fcn_blck)
/Murugan
  댓글 수: 1
Hadi Zyien
Hadi Zyien 2019년 6월 4일
Hi Murugan,
Unfortunately this approach also returns Stateflow charts.

댓글을 달려면 로그인하십시오.


Christophe Pouillot
Christophe Pouillot 2023년 11월 14일
편집: Christophe Pouillot 2023년 11월 14일
Use the following code lines to find MATLAB function blocks:
rt = sfroot;
m = rt.find('-isa','Stateflow.EMChart')
It uses the powerfull yet under-recognized Stateflow API https://fr.mathworks.com/help/stateflow/ref/sfroot.html
Despite its name, I believe it is available with Simulink alone.

카테고리

Help CenterFile Exchange에서 Simulink Functions에 대해 자세히 알아보기

제품


릴리스

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by