how can i bring 2 figures together?

1 vue (au cours des 30 derniers jours)
furkan aktürk
furkan aktürk le 29 Déc 2021
Modifié(e) : KSSV le 29 Déc 2021
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.

Réponse acceptée

DGM
DGM le 29 Déc 2021
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')

Plus de réponses (1)

KSSV
KSSV le 29 Déc 2021
Modifié(e) : KSSV le 29 Déc 2021
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'})

Catégories

En savoir plus sur Specifying Target for Graphics Output dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by