how can i bring 2 figures together?

1 回表示 (過去 30 日間)
furkan aktürk
furkan aktürk 2021 年 12 月 29 日
編集済み: KSSV 2021 年 12 月 29 日
clc
clear
x = [0.05 0.1 0.15 0.2 0.25 0.3 0.35 0.4 0.45 0.5];
y = 2+exp((-x).^3);
plot(x,y)
clc
clear
x (1)= 0;
y (1)= 3;
h = 0.05;
for i = 1:10
y (i+1)= y(i)+(6*x(i)^2-3*x(i)^2*y(i));
x (i+1)= x(i)+h;
end
plot(x,y,'-')
xlabel('x')
ylabel('y')
i want to show these two codes graphs in one figure. how can i do it ? btw x of two y are same but i couldnt use for different folder.

採用された回答

DGM
DGM 2021 年 12 月 29 日
If you look, the two x vectors are not the same. They differ in length by 1. You can reuse the latter x if you want. Either way, you can plot mutliple things in an axes using hold.
x(1) = 0;
y2(1) = 3;
h = 0.05;
for i = 1:10
y2(i+1) = y2(i)+(6*x(i)^2-3*x(i)^2*y2(i));
x(i+1) = x(i)+h;
end
y1 = 2+exp((-x).^3);
plot(x,y1,'-'); hold on
plot(x,y2,'-')
xlabel('x')
ylabel('y')

その他の回答 (1 件)

KSSV
KSSV 2021 年 12 月 29 日
編集済み: KSSV 2021 年 12 月 29 日
Read about hold on.
clc
clear
x1 = [0.05 0.1 0.15 0.2 0.25 0.3 0.35 0.4 0.45 0.5];
y1 = 2+exp((-x1).^3);
plot(x1,y1)
hold on
x (1)= 0;
y (1)= 3;
h = 0.05;
for i = 1:10
y (i+1)= y(i)+(6*x(i)^2-3*x(i)^2*y(i));
x (i+1)= x(i)+h;
end
plot(x,y,'-')
xlabel('x')
ylabel('y')
legend({'data1','data2'})

カテゴリ

Help Center および File ExchangeSpecifying Target for Graphics Output についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by