how can i bring 2 figures together?
1 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
采纳的回答
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')
0 个评论
更多回答(1 个)
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'})
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Specifying Target for Graphics Output 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!