필터 지우기
필터 지우기

Loop an if with different parameters

조회 수: 1 (최근 30일)
Brilliant Purnawan
Brilliant Purnawan 2020년 11월 15일
답변: Setsuna Yuuki. 2020년 11월 15일
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);

채택된 답변

Setsuna Yuuki.
Setsuna Yuuki. 2020년 11월 15일
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개)

카테고리

Help CenterFile Exchange에서 Graphics Performance에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by