Loop an if with different parameters
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Brilliant Purnawan
le 15 Nov 2020
Réponse apportée : Setsuna Yuuki.
le 15 Nov 2020
Hi, doing some practice codings and ran into a snag. So, i'm trying to plot(t,y) with different matrix 'e' values? Let's say my first 'e' would be [-1; -2; -3; -4], and second [-2; -3; -4; -5] and keeps increasing with increments of 1 until a maximum value of [-7; -8; -9; -10], and plot everything in the same graph? How would I go about this? Code is below
e = [-1; -2; -3; -4]
K = place(A,B,e);
tspan = 0:0.01:200;
if(c==-1)
y0=[0; 0; 0; 0];
[t,y] = ode45(@(t,y)Equation(y,m,M,l,g,b,-K*(y-[4; 0; 0; 0])),tspan,y0);
elseif(c==1)
y0=[-3; 0; pi+.1; 0];
[t,y] = ode45(@(t,y)Equation(y,m,M,l,g,b,-K*(y-[1; 0; pi; 0])),tspan,y0);
else
end
plot(t,y);
0 commentaires
Réponse acceptée
Setsuna Yuuki.
le 15 Nov 2020
You can use for to graph more than once.
for n=1:7
e = -n:-1:-n-3 % e values [-1 -2 -3 -4]
e = e'; %[-1;-2;-3;-4]
%Your code....
if(c==-1)
y0=[0; 0; 0; 0];
[t,y] = ode45(@(t,y)Equation(y,m,M,l,g,b,-K*(y-[4; 0; 0; 0])),tspan,y0);
elseif(c==1)
y0=[-3; 0; pi+.1; 0];
[t,y] = ode45(@(t,y)Equation(y,m,M,l,g,b,-K*(y-[1; 0; pi; 0])),tspan,y0);
else
end
% Your code end
plot(t,y); hold on;
end
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Graphics Performance dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!