Why is my animation so slow can someone help me ?

9 vues (au cours des 30 derniers jours)
Oguz Han Yesildal
Oguz Han Yesildal le 25 Mar 2019
Commenté : Walter Roberson le 25 Mar 2019
Hello I added some new things to my code, after this my programs runs very slow.
function [sys,x0,str,ts,simStateCompliance] = Berechnung(t,x,u,flag,P)
switch flag,
case 0,
[sys,x0,str,ts,simStateCompliance]=mdlInitializeSizes(P);
case 1,
sys=mdlDerivatives(t,x,u,P);
case 2,
sys=mdlUpdate(t,x,u);
case 3,
sys=mdlOutputs(t,x,u,P);
case 4,
sys=mdlGetTimeOfNextVarHit(t,x,u);
case 9,
sys=mdlTerminate(t,x,u);
otherwise
DAStudio.error('Simulink:blocks:unhandledFlag', num2str(flag));
end
function [sys,x0,str,ts,simStateCompliance]=mdlInitializeSizes(P)
sizes = simsizes;
sizes.NumContStates = 2;
sizes.NumDiscStates = 0;
sizes.NumOutputs = 2;
sizes.NumInputs = 2;
sizes.DirFeedthrough = 0;
sizes.NumSampleTimes = 1;
sys = simsizes(sizes);
x0 = [0; 0];
str = [];
ts = [0 0];
simStateCompliance = 'UnknownSimState';
function sys=mdlDerivatives(t,x,u,P)
h1 = x(1);
h2 = x(2);
ventilst = u(1);
pumpe = u(2);
v1 = P.v1_max*pumpe;
if h1 < 0
h1 = 0;
end
if h2 < 0
h2 = 0;
end
h1_dot = .1*((1-ventilst) * P.C1*v1 - P.C2*h1);
h2_dot = .1*-((1-ventilst) * P.C1*v1 - P.C2*h1);
if h1>=P.hT/1.4 && h1_dot>=0
h1_dot = 0;
end
if h1>=P.hT/1.4
h2_dot =0;
end
if ventilst== 1 && h1>=0
h1_dot = -1;
end
if ventilst== 1 && h1>=0
h2_dot = 1;
end
if ventilst== 1 && h1==0
h1_dot = 0;
h2_dot = 0;
end
if ventilst== 1
%Weißer Hintergrund
xbodenw1 = [-710 -710 -300 -300];
ybodenw1 = [-50 50 50 -50];
fill(xbodenw1,ybodenw1,'white','EdgeColor','white');
fill(xbodenw1,ybodenw1,'white','EdgeColor','white');
plot([-710 -710], [0 60], 'black');
%Knopf
plot([-450 -400], [-50 -50], 'k');
plot([-400 -400], [-50 -10], 'k');
plot([-450 -400], [-10 -10], 'k');
plot([-420 -430], [-50 -10], 'k');
%Feder11
plot([-650 -670], [-50 -25], 'black');
plot([-670 -690], [-25 -50], 'black');
plot([-690 -710], [-50 -25], 'black');
%RECHTECK BENTIL
plot([-550 -450], [50 50], 'k');
plot([-450 -450], [50 -50], 'k');
plot([-450 -550], [-50 -50], 'k');
plot([-550 -550], [-50 50], 'k');
%2
plot([-550 -650], [50 50], 'k');
plot([-650 -650], [50 -50], 'k');
plot([-650 -550], [-50 -50], 'k');
plot([-550 -550], [-50 50], 'k');
%Pfeil im Ventil
plot([-500 -500], [-50 50], 'black');
plot([-500 -490], [-50 -30], 'black');
plot([-500 -510], [-50 -30], 'black');
%Striche
plot([-600 -600], [49 24], 'black');
plot([-620 -580], [24 24], 'black');
plot([-600 -600], [-49 -24], 'black');
plot([-620 -580], [-24 -24], 'black');
end
if ventilst== 0
%Weißer Hintergrund
xbodenw2 = [-710 -710 -300 -300];
ybodenw2 = [-50 50 50 -50];
fill(xbodenw2,ybodenw2,'white','EdgeColor','white');
fill(xbodenw2,ybodenw2,'white','EdgeColor','white');
plot([-710 -710], [0 60], 'black');
%Knopf
plot([-350 -300], [-50 -50], 'k');
plot([-300 -300], [-50 -10], 'k');
plot([-350 -300], [-10 -10], 'k');
plot([-320 -330], [-50 -10], 'k');
%Feder11
plot([-550 -570], [-50 -25], 'black');
plot([-570 -590], [-25 -50], 'black');
plot([-590 -610], [-50 -25], 'black');
%RECHTECK BENTIL
plot([-450 -350], [50 50], 'k');
plot([-350 -350], [50 -50], 'k');
plot([-350 -450], [-50 -50], 'k');
plot([-450 -450], [-50 50], 'k');
%2
plot([-450 -550], [50 50], 'k');
plot([-550 -550], [50 -50], 'k');
plot([-550 -450], [-50 -50], 'k');
plot([-450 -450], [-50 50], 'k');
%Pfeil im Ventil
plot([-400 -400], [-50 50], 'black');
plot([-400 -390], [-50 -30], 'black');
plot([-400 -410], [-50 -30], 'black');
%Striche
plot([-500 -500], [49 24], 'black');
plot([-520 -480], [24 24], 'black');
plot([-500 -500], [-49 -24], 'black');
plot([-520 -480], [-24 -24], 'black');
end
sys = [h1_dot; h2_dot];
function sys=mdlUpdate(t,x,u)
sys = [];
function sys=mdlOutputs(t,x,u,P)
h1 = x(1);
h2 = x(2);
sys = [h1;h2];
function sys=mdlGetTimeOfNextVarHit(t,x,u)
sampleTime = 1;
sys = t + sampleTime;
function sys=mdlTerminate(t,x,u)
sys = [];
  1 commentaire
Walter Roberson
Walter Roberson le 25 Mar 2019
One thing I would suggest would be to reduce the number of plot() calls.
plot([x11 x12], [y11 y12], 'black')
plot([x21 x22], [y21 y22], 'black')
can be drawn by
plot([x11 x12 nan x21 x22], [y11 y12 nan y21 y22], 'black')
which reduces the number of plot objects.
I notice that you do not have any "hold on" or "hold off". Either only the very last thing would be drawn, or else you have "hold on" somewhere else outside of this, in which case you have the problem that every time the function is called that you are plotting additional objects on top of what you have already drawn.

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Line Plots dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by