概述
%% 获取Simulink模型下特定SubSystem的Port名称
clc;
clear;
bdclose;
[filename, pathname] = uigetfile({'*.slx';'*.mdl';'*.*'}, 'Select a Simulink Model file');
if isequal(filename,0)
disp('User selected Cancel')
else
disp(['User selected ', fullfile(pathname, filename)])
end
load_system([pathname,filename]);
%% find 'In_S' SubSystem
[pathstr,name,ext] = fileparts(filename);
str = find_system(name,'SearchDepth',1,'BlockType','SubSystem');
k = contains(str,'In_S');
Objects = find_system(str(k),'SearchDepth',1,'BlockType','Inport');
portName = get_param(Objects,'Name');
% 以下划线为分隔符,取第一个下划线前的字符为Name
expression = '_';
splitStr = regexp(portName,expression,'split');
for nn = 1:length(portName)
In_S_InportName{nn,1} = splitStr{nn,1}{1,1};
end
Objects = find_system(str(k),'SearchDepth',1,'BlockType','Outport');
portName = get_param(Objects,'Name');
% 以下划线为分隔符,取第一个下划线前的字符为Name
expression = '_';
splitStr = regexp(portName,expression,'split');
for nn = 1:length(portName)
In_S_OutportName{nn,1} = splitStr{nn,1}{1,1};
end
%% find 'Out_S' SubSystem
k = contains(str,'Out_S');
Objects = find_system(str(k),'SearchDepth',1,'BlockType','Inport');
portName = get_param(Objects,'Name');
expression = '_';
splitStr = regexp(portName,expression,'split');
for nn = 1:length(portName)
Out_S_InportName{nn,1} = splitStr{nn,1}{1,1};
end
Objects = find_system(str(k),'SearchDepth',1,'BlockType','Outport');
portName = get_param(Objects,'Name');
expression = '_';
splitStr = regexp(portName,expression,'split');
for nn = 1:length(portName)
Out_S_OutportName{nn,1} = splitStr{nn,1}{1,1};
end
clearvars -except In_S_InportName In_S_OutportName Out_S_InportName Out_S_OutportName
最后
以上就是现代人生为你收集整理的获取Simulink模型 SubSystem Port名称的全部内容,希望文章能够帮你解决获取Simulink模型 SubSystem Port名称所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复