Azzera filtri
Azzera filtri

Loop an if with different parameters

1 visualizzazione (ultimi 30 giorni)
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);

Risposta accettata

Setsuna Yuuki.
Setsuna Yuuki. il 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

Più risposte (0)

Categorie

Scopri di più su Graphics Performance in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by