How can I draw a six graph together in one figure using plot and hold on?

1 回表示 (過去 30 日間)
Meriem Noor
Meriem Noor 2021 年 1 月 21 日
コメント済み: Meriem Noor 2021 年 1 月 21 日
I want to have six diagrams in different colors in one figure, but the program that I wrote only gives me one graph.
j=0;
for xi=0.01:0.02:0.11;
j=j+1;
i1=0;
for bT=0.01:0.01:5
i1=i1+1;
r=xi;
mass=1;
tn=bT; % période naturelle
wn=2.0*pi/tn; % pulsation naturelle
k=mass*wn^2; %Rigidité
wd=wn*sqrt(1-r^2); %Pulsation amortie
a=exp(-r*wn*dt)*(r*sin(wd*dt)/sqrt(1-r^2)+cos(wd*dt));
b=exp(-r*wn*dt)*(sin(wd*dt))/wd;
c2=((1-2*r^2)/(wd*dt)-r/sqrt(1-r^2))*sin(wd*dt)-(1+2*r/(wn*dt))*cos(wd*dt);
c=(1/k)*(2*r/(wn*dt)+exp(-r*wn*dt)*(c2));
d2=exp(-r*wn*dt)*((2.0*r^2-1)/(wd*dt)*sin(wd*dt)+2.0*r/(wn*dt)*cos(wd*dt));
d=(1/k)*(1-2.0*r/(wn*dt)+d2);
ad=-exp(-r*wn*dt)*wn*sin(wd*dt)/(sqrt(1-r^2));
bd=exp(-r*wn*dt)*(cos(wd*dt)-r*sin(wd*dt)/sqrt(1-r^2));
c1 = exp(-r*wn*dt)*((wn/sqrt(1-r^2)+r/(dt*sqrt(1-r^2)))*sin(wd*dt)+cos(wd*dt)/dt);
cd=(1/k)*(-1/dt+c1);
d1=exp(-r*wn*dt)*(r*sin(wd*dt)/sqrt(1-r^2)+cos(wd*dt));
dd=(1/(k*dt))*(1-d1);
for m=2:n1
u(m)=a*u(m-1)+b*v(m-1)+c*p(m-1)+d*p(m);
v(m)=ad*u(m-1)+bd*v(m-1)+cd*p(m-1)+dd*p(m);
ta(m)=(-2*r*wn*v(m)-wn*wn*u(m))/mass;
end
T(i1)=bT;
K(i1,j)=max(abs(u));
end
end
for Q=1,6;
plot(T,K(:,Q));
end

採用された回答

Cris LaPierre
Cris LaPierre 2021 年 1 月 21 日
Did you try to use hold? Also, your for loop syntax appears to be wrong. You also have several undefined variables.
hold on
for Q=1:6
plot(T,K(:,Q));
end
hold off
  3 件のコメント
Cris LaPierre
Cris LaPierre 2021 年 1 月 21 日
Also, see the Color section of the plot documentation page.
Meriem Noor
Meriem Noor 2021 年 1 月 21 日
Thanks a lot for the help

サインインしてコメントする。

その他の回答 (1 件)

dpb
dpb 2021 年 1 月 21 日
Replace
for Q=1,6;
plot(T,K(:,Q));
end
with
hL=plot(T,K);
plot (like almost all MATLAB functions) operates by column and treats columns as independent variables.
To do one at a time explicitly (like if you were to plot() each when generated instead of waiting to the end), then you need a
hold on
statement either first or after the first call to plot() to add to the axes.
See
doc hold
doc plot
for details on each with examples.

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by