Matching port number in two simulink model

조회 수: 1 (최근 30일)
Hariom Singh
Hariom Singh 2018년 9월 19일
답변: Raghunandan V 2018년 10월 5일
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에서 Subsystems에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by