Matching port number in two simulink model

7 次查看(过去 30 天)
I have two simulink model , both of them has same signal names but are assigned with different port number . For example
model1.slx
Engine_State_ECU_1_1_3 port number is 23
same in
model2.slx
Engine_State_ECU_1_1_3 port number is 25
There are almost 2 thousand such port how to synchronize port numbers

采纳的回答

Raghunandan V
Raghunandan V 2018-10-5
%find all inports from both system
Allinports1=find_system('PortSync/Subsystem1','BlockType','Inport');
Allinports2=find_system('PortSync/Subsystem2','BlockType','Inport');
for k=1: length(Allinports1)
%get the port number of all the inports in the first subsystem
PortNum=get_param(Allinports1{k,1},'Port');
%to find the port name only you have to find the '/' indexes
Index1=strfind(Allinports1{k,1},'/');
%once you find the indices, we know that the port name is the last part
%of the full address of the port
PortName1=Allinports1{k,1}((Index1(end)+1):end);
for j=1: length(Allinports2)
%same steps as above is followed for the second subsystem too
Index2=strfind(Allinports2{j,1},'/');
PortName2=Allinports2{j,1}((Index2(end)+1):end);
%if there is a common name then set the second subsystem port number same
%as first one
if PortName1==PortName2
set_param(Allinports2{j,1},'Port',PortNum);
end
end
end

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Modeling 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by