my plotting in for loop running slow (7th Adam Bashfort/6th Adam Moulton and 7th Runge kutta
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I have this program. This program is about to solve ODE system and i'm using 7/6 Steps ABM and RK4 as my start value.
please try my code below :
My code is running very slow and based on my possible duplicate (of a question about "the code is running slow"), this is happen because of my plotting is in the for loop instead of at the end of the script. But, if i do that, i mean remove it and place it at the end of the script, my plotting becomes ugly and messed up.
BUT, my code run faster than before, yeah i still have a problem, it messes up my plot graph. it means, my plot graph MUST BE placed in the for loop.
please help, my goal is i wanna run this program fastly and the graph is still looks good.
Thanks in advance
clear all;
close all;
clc;
disp('=======================================');
disp('SEVEN STEPS AB - SIX STEPS AM AND RK7 ');
disp('=======================================');
% ODE SYSTEM
fS = @(t,S,E,I,R)(0-((0.5)*I + 0.25)*S);
fE = @(t,S,E,I,R)(0.5*S*I - E);
fI = @(t,S,E,I,R)(0.75*E - I);
fR = @(t,S,E,I,R)(0.75*I - 0.25*R);
t0 = input('input t (input 1)= ');
S0 = input('input S0 (input 1)= ');
E0 = input('input E0 (input 0)= ');
I0 = input('input I0 (input 1)= ');
R0 = input('input R0 (input 0)= ');
h = 0.01;
n = ceil(t0/h);
t(1) = t0;
S(1) = S0;
E(1) = E0;
I(1) = I0;
R(1) = R0;
disp('_______________________________________________________________________');
fprintf(' i x S E I R \n');
disp('_______________________________________________________________________');
fprintf('%4.f %5.4f %11.8f %11.8f %11.8f %11.8f\n',i,t(1),S(1),E(1),I(1),R(1));
for i = 1:6
t(i+1) = t(i)+h;
k1S = fS(t(i),S(i),E(i),I(i),R(i));
k1E = fE(t(i),S(i),E(i),I(i),R(i));
k1I = fI(t(i),S(i),E(i),I(i),R(i));
k1R = fR(t(i),S(i),E(i),I(i),R(i));
k2S = fS(t(i)+h/12, S(i)+h*k1S/12, E(i)+h*k1E/12, I(i)+h*k1I/12,R(i)+h*k1R/12);
k2E = fE(t(i)+h/12, S(i)+h*k1S/12, E(i)+h*k1E/12, I(i)+h*k1I/12,R(i)+h*k1R/12);
k2I = fI(t(i)+h/12, S(i)+h*k1S/12, E(i)+h*k1E/12, I(i)+h*k1I/12,R(i)+h*k1R/12);
k2R = fR(t(i)+h/12, S(i)+h*k1S/12, E(i)+h*k1E/12, I(i)+h*k1I/12,R(i)+h*k1R/12);
k3S = fS(t(i)+h/6, S(i)+h/6*(k2S), E(i)+h/6*(k2E), I(i)+h/6*(k2I),R(i)+h/6*(k2R));
k3E = fE(t(i)+h/6, S(i)+h/6*(k2S), E(i)+h/6*(k2E), I(i)+h/6*(k2I),R(i)+h/6*(k2R));
k3I = fI(t(i)+h/6, S(i)+h/6*(k2S), E(i)+h/6*(k2E), I(i)+h/6*(k2I),R(i)+h/6*(k2R));
k3R = fR(t(i)+h/6, S(i)+h/6*(k2S), E(i)+h/6*(k2E), I(i)+h/6*(k2I),R(i)+h/6*(k2R));
k4S = fS(t(i)+h/4, S(i)+h/16*(k1S+3*k3S), E(i)+h/16*(k1E+3*k3E),I(i)+h/16*(k1I+3*k3I), R(i)+h/16*(k1R+3*k3R));
k4E = fE(t(i)+h/4, S(i)+h/16*(k1S+3*k3S), E(i)+h/16*(k1E+3*k3E),I(i)+h/16*(k1I+3*k3I), R(i)+h/16*(k1R+3*k3R));
k4I = fI(t(i)+h/4, S(i)+h/16*(k1S+3*k3S), E(i)+h/16*(k1E+3*k3E),I(i)+h/16*(k1I+3*k3I), R(i)+h/16*(k1R+3*k3R));
k4R = fR(t(i)+h/4, S(i)+h/16*(k1S+3*k3S), E(i)+h/16*(k1E+3*k3E),I(i)+h/16*(k1I+3*k3I), R(i)+h/16*(k1R+3*k3R));
k5S = fS(t(i)+3*h/4, S(i)+h/16*(21*k1S - 81*k3S + 72*k4S), E(i)+h/16*(21*k1E - 81*k3E + 72*k4E),I(i)+h/16*(21*k1I - 81*k3I +72*k4I), R(i)+h/16*(21*k1R - 81*k3R + 72*k4R));
k5E = fE(t(i)+3*h/4, S(i)+h/16*(21*k1S - 81*k3S + 72*k4S), E(i)+h/16*(21*k1E - 81*k3E + 72*k4E),I(i)+h/16*(21*k1I - 81*k3I +72*k4I), R(i)+h/16*(21*k1R - 81*k3R + 72*k4R));
k5I = fI(t(i)+3*h/4, S(i)+h/16*(21*k1S - 81*k3S + 72*k4S), E(i)+h/16*(21*k1E - 81*k3E + 72*k4E),I(i)+h/16*(21*k1I - 81*k3I +72*k4I), R(i)+h/16*(21*k1R - 81*k3R + 72*k4R));
k5R = fR(t(i)+3*h/4, S(i)+h/16*(21*k1S - 81*k3S + 72*k4S), E(i)+h/16*(21*k1E - 81*k3E + 72*k4E),I(i)+h/16*(21*k1I - 81*k3I +72*k4I), R(i)+h/16*(21*k1R - 81*k3R + 72*k4R));
k6S = fS(t(i)+16*h/17, S(i)+h/250563*(1344688*k1S- 5127552*k3S + 4096896*k4S - 78208*k5S), E(i)+h/250563*(1344688*k1E - 5127552*k3E + 4096896*k4E - 78208*k5E), I(i)+h/250563*(1344688*k1I - 5127552*k3I + 4096896*k4I - 78208*k5I),R(i)+h/250563*(1344688*k1R - 5127552*k3R + 4096896*k4R -78208*k5R));
k6E = fE(t(i)+16*h/17, S(i)+h/250563*(1344688*k1S- 5127552*k3S + 4096896*k4S - 78208*k5S), E(i)+h/250563*(1344688*k1E - 5127552*k3E + 4096896*k4E - 78208*k5E), I(i)+h/250563*(1344688*k1I - 5127552*k3I + 4096896*k4I - 78208*k5I),R(i)+h/250563*(1344688*k1R - 5127552*k3R + 4096896*k4R -78208*k5R));
k6I = fI(t(i)+16*h/17, S(i)+h/250563*(1344688*k1S- 5127552*k3S + 4096896*k4S - 78208*k5S), E(i)+h/250563*(1344688*k1E - 5127552*k3E + 4096896*k4E - 78208*k5E), I(i)+h/250563*(1344688*k1I - 5127552*k3I + 4096896*k4I - 78208*k5I),R(i)+h/250563*(1344688*k1R - 5127552*k3R + 4096896*k4R -78208*k5R));
k6R = fR(t(i)+16*h/17, S(i)+h/250563*(1344688*k1S- 5127552*k3S + 4096896*k4S - 78208*k5S), E(i)+h/250563*(1344688*k1E - 5127552*k3E + 4096896*k4E - 78208*k5E), I(i)+h/250563*(1344688*k1I - 5127552*k3I + 4096896*k4I - 78208*k5I),R(i)+h/250563*(1344688*k1R - 5127552*k3R + 4096896*k4R -78208*k5R));
k7S = fS(t(i)+h/2, S(i)+h/234624*( -341549*k1S + 1407744*k3S- 1018368*k4S + 84224*k5S - 14739*k6S), E(i)+h/234624*( -341549*k1E + 1407744*k3E - 1018368*k4E + 84224*k5E -14739*k6E), I(i)+h/234624*( -341549*k1I + 1407744*k3I -1018368*k4I + 84224*k5I - 14739*k6I), R(i)+h/234624*( -341549*k1R + 1407744*k3R - 1018368*k4R + 84224*k5R -14739*k6R));
k7E = fE(t(i)+h/2, S(i)+h/234624*( -341549*k1S + 1407744*k3S- 1018368*k4S + 84224*k5S - 14739*k6S), E(i)+h/234624*( -341549*k1E + 1407744*k3E - 1018368*k4E + 84224*k5E -14739*k6E), I(i)+h/234624*( -341549*k1I + 1407744*k3I -1018368*k4I + 84224*k5I - 14739*k6I), R(i)+h/234624*( -341549*k1R + 1407744*k3R - 1018368*k4R + 84224*k5R -14739*k6R));
k7I = fI(t(i)+h/2, S(i)+h/234624*( -341549*k1S + 1407744*k3S- 1018368*k4S + 84224*k5S - 14739*k6S), E(i)+h/234624*( -341549*k1E + 1407744*k3E - 1018368*k4E + 84224*k5E -14739*k6E), I(i)+h/234624*( -341549*k1I + 1407744*k3I -1018368*k4I + 84224*k5I - 14739*k6I), R(i)+h/234624*( -341549*k1R + 1407744*k3R - 1018368*k4R + 84224*k5R -14739*k6R));
k7R = fR(t(i)+h/2, S(i)+h/234624*( -341549*k1S + 1407744*k3S- 1018368*k4S + 84224*k5S - 14739*k6S), E(i)+h/234624*( -341549*k1E + 1407744*k3E - 1018368*k4E + 84224*k5E -14739*k6E), I(i)+h/234624*( -341549*k1I + 1407744*k3I -1018368*k4I + 84224*k5I - 14739*k6I), R(i)+h/234624*( -341549*k1R + 1407744*k3R - 1018368*k4R + 84224*k5R -14739*k6R));
k8S = fS(t(i)+h, S(i)+h/136864*( -381875*k1S + 1642368*k3S- 1327872*k4S + 72192*k5S + 14739*k6S + 117312*k7S), E(i)+h/136864*( -381875*k1E + 1642368*k3E - 1327872*k4E + 72192*k5E +14739*k6E + 117312*k7E), I(i)+h/136864*( -381875*k1I +1642368*k3I - 1327872*k4I + 72192*k5I + 14739*k6I + 117312*k7I),R(i)+h/136864*( -381875*k1R + 1642368*k3R - 1327872*k4R +72192*k5R + 14739*k6R + 117312*k7R));
k8E = fE(t(i)+h, S(i)+h/136864*( -381875*k1S + 1642368*k3S- 1327872*k4S + 72192*k5S + 14739*k6S + 117312*k7S), E(i)+h/136864*( -381875*k1E + 1642368*k3E - 1327872*k4E + 72192*k5E +14739*k6E + 117312*k7E), I(i)+h/136864*( -381875*k1I +1642368*k3I - 1327872*k4I + 72192*k5I + 14739*k6I + 117312*k7I),R(i)+h/136864*( -381875*k1R + 1642368*k3R - 1327872*k4R +72192*k5R + 14739*k6R + 117312*k7R));
k8I = fI(t(i)+h, S(i)+h/136864*( -381875*k1S + 1642368*k3S- 1327872*k4S + 72192*k5S + 14739*k6S + 117312*k7S), E(i)+h/136864*( -381875*k1E + 1642368*k3E - 1327872*k4E + 72192*k5E +14739*k6E + 117312*k7E), I(i)+h/136864*( -381875*k1I +1642368*k3I - 1327872*k4I + 72192*k5I + 14739*k6I + 117312*k7I),R(i)+h/136864*( -381875*k1R + 1642368*k3R - 1327872*k4R +72192*k5R + 14739*k6R + 117312*k7R));
k8R = fR(t(i)+h, S(i)+h/136864*( -381875*k1S + 1642368*k3S- 1327872*k4S + 72192*k5S + 14739*k6S + 117312*k7S), E(i)+h/136864*( -381875*k1E + 1642368*k3E - 1327872*k4E + 72192*k5E +14739*k6E + 117312*k7E), I(i)+h/136864*( -381875*k1I +1642368*k3I - 1327872*k4I + 72192*k5I + 14739*k6I + 117312*k7I),R(i)+h/136864*( -381875*k1R + 1642368*k3R - 1327872*k4R +72192*k5R + 14739*k6R + 117312*k7R));
k9S = fS(t(i)+2*h/3, S(i)+h/16755336*( -2070757*k1S + 9929088*k3S+ 584064*k4S + 3023488*k5S - 447083*k6S + 151424*k7S), E(i)+h/16755336*( -2070757*k1E + 9929088*k3E + 584064*k4E +3023488*k5E - 447083*k6E + 151424*k7E), I(i)+h/16755336*( -2070757*k1I + 9929088*k3I + 584064*k4I + 3023488*k5I -447083*k6I + 151424*k7I), R(i)+h/16755336*( -2070757*k1R +9929088*k3R + 584064*k4R + 3023488*k5R - 447083*k6R + 151424*k7R));
k9E = fE(t(i)+2*h/3, S(i)+h/16755336*( -2070757*k1S + 9929088*k3S+ 584064*k4S + 3023488*k5S - 447083*k6S + 151424*k7S), E(i)+h/16755336*( -2070757*k1E + 9929088*k3E + 584064*k4E +3023488*k5E - 447083*k6E + 151424*k7E), I(i)+h/16755336*( -2070757*k1I + 9929088*k3I + 584064*k4I + 3023488*k5I -447083*k6I + 151424*k7I), R(i)+h/16755336*( -2070757*k1R +9929088*k3R + 584064*k4R + 3023488*k5R - 447083*k6R + 151424*k7R));
k9I = fI(t(i)+2*h/3, S(i)+h/16755336*( -2070757*k1S + 9929088*k3S+ 584064*k4S + 3023488*k5S - 447083*k6S + 151424*k7S), E(i)+h/16755336*( -2070757*k1E + 9929088*k3E + 584064*k4E +3023488*k5E - 447083*k6E + 151424*k7E), I(i)+h/16755336*( -2070757*k1I + 9929088*k3I + 584064*k4I + 3023488*k5I -447083*k6I + 151424*k7I), R(i)+h/16755336*( -2070757*k1R +9929088*k3R + 584064*k4R + 3023488*k5R - 447083*k6R + 151424*k7R));
k9R = fR(t(i)+2*h/3, S(i)+h/16755336*( -2070757*k1S + 9929088*k3S+ 584064*k4S + 3023488*k5S - 447083*k6S + 151424*k7S), E(i)+h/16755336*( -2070757*k1E + 9929088*k3E + 584064*k4E +3023488*k5E - 447083*k6E + 151424*k7E), I(i)+h/16755336*( -2070757*k1I + 9929088*k3I + 584064*k4I + 3023488*k5I -447083*k6I + 151424*k7I), R(i)+h/16755336*( -2070757*k1R +9929088*k3R + 584064*k4R + 3023488*k5R - 447083*k6R + 151424*k7R));
k10S= fS(t(i)+h, S(i)+h/10743824*( 130521209*k1S - 499279872*k3S -391267968*k4S + 13012608*k5S - 3522621*k6S + 9033024*k7S- 30288492*k9S), E(i)+h/10743824*( 130521209*k1E - 499279872*k3E -391267968*k4E + 13012608*k5E - 3522621*k6E + 9033024*k7E- 30288492*k9E), I(i)+h/10743824*( 130521209*k1I - 499279872*k3I -391267968*k4I + 13012608*k5I - 3522621*k6I + 9033024*k7I- 30288492*k9I), R(i)+h/10743824*( 130521209*k1R - 499279872*k3R -391267968*k4R + 13012608*k5R - 3522621*k6R + 9033024*k7R- 30288492*k9R));
k10E= fS(t(i)+h, S(i)+h/10743824*( 130521209*k1S - 499279872*k3S -391267968*k4S + 13012608*k5S - 3522621*k6S + 9033024*k7S- 30288492*k9S), E(i)+h/10743824*( 130521209*k1E - 499279872*k3E -391267968*k4E + 13012608*k5E - 3522621*k6E + 9033024*k7E- 30288492*k9E), I(i)+h/10743824*( 130521209*k1I - 499279872*k3I -391267968*k4I + 13012608*k5I - 3522621*k6I + 9033024*k7I- 30288492*k9I), R(i)+h/10743824*( 130521209*k1R - 499279872*k3R -391267968*k4R + 13012608*k5R - 3522621*k6R + 9033024*k7R- 30288492*k9R));
k10I= fS(t(i)+h, S(i)+h/10743824*( 130521209*k1S - 499279872*k3S -391267968*k4S + 13012608*k5S - 3522621*k6S + 9033024*k7S- 30288492*k9S), E(i)+h/10743824*( 130521209*k1E - 499279872*k3E -391267968*k4E + 13012608*k5E - 3522621*k6E + 9033024*k7E- 30288492*k9E), I(i)+h/10743824*( 130521209*k1I - 499279872*k3I -391267968*k4I + 13012608*k5I - 3522621*k6I + 9033024*k7I- 30288492*k9I), R(i)+h/10743824*( 130521209*k1R - 499279872*k3R -391267968*k4R + 13012608*k5R - 3522621*k6R + 9033024*k7R- 30288492*k9R));
k10R= fS(t(i)+h, S(i)+h/10743824*( 130521209*k1S - 499279872*k3S -391267968*k4S + 13012608*k5S - 3522621*k6S + 9033024*k7S- 30288492*k9S), E(i)+h/10743824*( 130521209*k1E - 499279872*k3E -391267968*k4E + 13012608*k5E - 3522621*k6E + 9033024*k7E- 30288492*k9E), I(i)+h/10743824*( 130521209*k1I - 499279872*k3I -391267968*k4I + 13012608*k5I - 3522621*k6I + 9033024*k7I- 30288492*k9I), R(i)+h/10743824*( 130521209*k1R - 499279872*k3R -391267968*k4R + 13012608*k5R - 3522621*k6R + 9033024*k7R- 30288492*k9R));
S(i+1) = S(i)+h/90*(7*k1S+32*k4S+32*k5S+12*k7S+7*k8S);
E(i+1) = E(i)+h/90*(7*k1E+32*k4E+32*k5E+12*k7E+7*k8E);
I(i+1) = I(i)+h/90*(7*k1I+32*k4I+32*k5I+12*k7I+7*k8I);
R(i+1) = R(i)+h/90*(7*k1R+32*k4R+32*k5R+12*k7R+7*k8R);
fprintf('%4.f %5.4f %11.8f %11.8f %11.8f %11.8f\n',i,t(i+1),S(i+1),E(i+1),I(i+1),R(i+1));
plot(t,S,'r')
hold on
plot(t,E,'b')
hold on
plot(t,I,'g')
hold on
plot(t,R,'k')
hold on
title('Adam-Bashforth-Method'); grid on
xlabel('time(10 years)','Fontsize',10)
ylabel('the number of computers ','Fontsize',10)
legend('Susceptible','Exposed','Infectiuos','Recovered')
end
for i = 7:n
tt0 = t0+i*h;
predS = S(7) + h*(198721*fS(t(7),S(7),E(7),I(7),R(7)) - 447288*fS(t(6),S(6),E(6),I(6),R(6)) + 705549*fS(t(5),S(5),E(5),I(5),R(5)) - 688256*fS(t(4),S(4),E(4),I(4),R(4)) + 407139*fS(t(3),S(3),E(3),I(3),R(3)) -134472*fS(t(2),S(2),E(2),I(2),R(2)) + 19087*fS(t(1),S(1),E(1),I(1),R(1)))/60480;
predE = E(7) + h*(198721*fE(t(7),S(7),E(7),I(7),R(7)) - 447288*fE(t(6),S(6),E(6),I(6),R(6)) + 705549*fE(t(5),S(5),E(5),I(5),R(5)) - 688256*fE(t(4),S(4),E(4),I(4),R(4)) + 407139*fE(t(3),S(3),E(3),I(3),R(3)) -134472*fE(t(2),S(2),E(2),I(2),R(2)) + 19087*fE(t(1),S(1),E(1),I(1),R(1)))/60480;
predI = I(7) + h*(198721*fI(t(7),S(7),E(7),I(7),R(7)) - 447288*fI(t(6),S(6),E(6),I(6),R(6)) + 705549*fI(t(5),S(5),E(5),I(5),R(5)) - 688256*fI(t(4),S(4),E(4),I(4),R(4)) + 407139*fI(t(3),S(3),E(3),I(3),R(3)) -134472*fI(t(2),S(2),E(2),I(2),R(2)) + 19087*fI(t(1),S(1),E(1),I(1),R(1)))/60480;
predR = R(7) + h*(198721*fR(t(7),S(7),E(7),I(7),R(7)) - 447288*fR(t(6),S(6),E(6),I(6),R(6)) + 705549*fR(t(5),S(5),E(5),I(5),R(5)) - 688256*fR(t(4),S(4),E(4),I(4),R(4)) + 407139*fR(t(3),S(3),E(3),I(3),R(3)) -134472*fR(t(2),S(2),E(2),I(2),R(2)) + 19087*fR(t(1),S(1),E(1),I(1),R(1)))/60480;
predS = S(7) + h*(19087*fS(tt0,predS,predE,predI,predR) + 65112*fS(t(7),S(7),E(7),I(7),R(7)) - 46461*fS(t(6),S(6),E(6),I(6),R(6)) + 37504*fS(t(5),S(5),E(5),I(5),R(5)) - 20211*fS(t(4),S(4),E(4),I(4),R(4)) + 6312*fS(t(3),S(3),E(3),I(3),R(3)) - 863*fS(t(2),S(2),E(2),I(2),R(2)))/60480;
predE = E(7) + h*(19087*fE(tt0,predS,predE,predI,predR) + 65112*fE(t(7),S(7),E(7),I(7),R(7)) - 46461*fE(t(6),S(6),E(6),I(6),R(6)) + 37504*fE(t(5),S(5),E(5),I(5),R(5)) - 20211*fE(t(4),S(4),E(4),I(4),R(4)) + 6312*fE(t(3),S(3),E(3),I(3),R(3)) - 863*fE(t(2),S(2),E(2),I(2),R(2)))/60480;
predI = I(7) + h*(19087*fI(tt0,predS,predE,predI,predR) + 65112*fI(t(7),S(7),E(7),I(7),R(7)) - 46461*fI(t(6),S(6),E(6),I(6),R(6)) + 37504*fI(t(5),S(5),E(5),I(5),R(5)) - 20211*fI(t(4),S(4),E(4),I(4),R(4)) + 6312*fI(t(3),S(3),E(3),I(3),R(3)) - 863*fI(t(2),S(2),E(2),I(2),R(2)))/60480;
predR = R(7) + h*(19087*fR(tt0,predS,predE,predI,predR) + 65112*fR(t(7),S(7),E(7),I(7),R(7)) - 46461*fR(t(6),S(6),E(6),I(6),R(6)) + 37504*fR(t(5),S(5),E(5),I(5),R(5)) - 20211*fR(t(4),S(4),E(4),I(4),R(4)) + 6312*fR(t(3),S(3),E(3),I(3),R(3)) - 863*fR(t(2),S(2),E(2),I(2),R(2)))/60480;
fprintf('%4.f %5.4f %11.8f %11.8f %11.8f %11.8f\n',i,tt0,predS,predE,predI,predR);
for j = 1:6
t(j) = t(j+1);
S(j) = S(j+1);
E(j) = E(j+1);
I(j) = I(j+1);
R(j) = R(j+1);
end
t(7)=tt0;
S(7)=predS;
E(7)=predE;
I(7)=predI;
R(7)=predR;
plot(t,S,'r')
hold on
plot(t,E,'b')
hold on
plot(t,I,'g')
hold on
plot(t,R,'k')
title('Adam-Bashforth-Method'); grid on
xlabel('time(10 years)','Fontsize',10)
ylabel('the number of computers ','Fontsize',10)
legend('Susceptible','Exposed','Infectiuos','Recovered')
end
hold off
disp(['jumlah iterasi = ',num2str(i)]);
fprintf('The result of yS with 7th ABM= %11.10f\n',predS);
% disp(['The result of y with 7th ABM= ', num2str(predS)]);
fprintf('The result of yE with 7th ABM= %11.10f\n',predE);
% disp(['The result of y with 7th ABM= ', num2str(predE)]);
fprintf('The result of yI with 7th ABM= %11.10f\n',predI);
% disp(['The result of y with 7th ABM= ', num2str(predI)]);
fprintf('The result of yR with 7th ABM= %11.10f\n',predR);
% disp(['The result of y with 7th ABM= ', num2str(predR)]);
0 Kommentare
Antworten (1)
Steven Lord
am 16 Dez. 2019
Rather than keeping on adding in many, many new lines (each call to plot, because you have hold on, will add a new line to the axes) that consume memory, why not create animatedline objects prior to your loop and addpoints to the appropriate animatedline inside the loop? That way you only have a fixed (small) number of lines which will grow in memory consumption much more slowly than creating whole new lines each iteration.
You should also move the commands to create the title and the legend and to set the grid, xlabel, and ylabel outside the loop. They don't depend on the loop variables, so calling them over and over just takes time without making any change to the figure.
1 Kommentar
Siehe auch
Kategorien
Mehr zu Specifying Target for Graphics Output finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!