Implementing a For loop in Simulink model

1 回表示 (過去 30 日間)
Pratik Panchal
Pratik Panchal 2020 年 6 月 11 日
Hello All,
I have a matlab code that consists of a for loop. The for loop iterates from 1 up to 2000. During each iteration, it plots an object through a patch command. The coordinate matrices updates afterwards in each iteration. Meaning I can see the object moving in the plot window.
My question is, how do I implement the same code in Simulink?
So far, I have tried with the 'For iterator Subsystem' in a fixed-step simulation. However, the for iterator subsystem iterates for a number of times in a single steps. Where as I need an ouput matrix with each iteration of 'For iterator Subsystem' that I can use as an input to patch command.
for zu=1:2000
[SowjEcken_neu]=Sowjet_Bewegung(SowjEcken_neu,SowjEcken,SowjFlaechen,SowjFlaechen2,rx,ry,rz,sT)
[Ecken_neu]=USA_Bewegung(Ecken_neu,Ecken,Flaechen1,Flaechen2,Flaechen3,T,rx,ry,rz)
newplot
%USA
patch ('Vertices',Ecken_neu,'Faces',Flaechen1,'FaceColor',[0 0 1])
patch ('Vertices',Ecken_neu,'Faces',Flaechen2,'FaceColor',[0 0 1])
patch ('Vertices',Ecken_neu,'Faces',Flaechen3,'FaceColor',[0 0 1])
%SOWJET
patch ('Vertices',SowjEcken_neu,'Faces',SowjFlaechen,'FaceColor',[1 1 0])
patch ('Vertices',SowjEcken_neu,'Faces',SowjFlaechen2,'FaceColor',[1 0 0])
A=60;
axis ([-A A -A A -A A])
view(3)
drawnow
%Parameter-USA
rz = rz+0.1;
rx = rx+0.2;
ry = ry+0.1;
w=w+0.01;
l=-24*sin(w);
p=21*cos(w);
k=0;
T(1:3,4) = [l;p;k];
%Parameter-Sowjet
sw=sw+0.02
sl=25*sin(sw);
sp=0;
sk=34*cos(sw);
sT(1:3,4) = [sl;sp;sk];
%Hintergrundfarbe
fig = gcf;
fig.Color = [0.5 0.5 0.5];
end

回答 (0 件)

カテゴリ

Help Center および File ExchangePolygons についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by